1*41ec0267Sriastradh /* $NetBSD: qxl_object.h,v 1.3 2021/12/18 23:45:42 riastradh Exp $ */
2efa246c0Sriastradh
39d20d926Sriastradh /*
49d20d926Sriastradh * Copyright 2013 Red Hat Inc.
59d20d926Sriastradh *
69d20d926Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
79d20d926Sriastradh * copy of this software and associated documentation files (the "Software"),
89d20d926Sriastradh * to deal in the Software without restriction, including without limitation
99d20d926Sriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense,
109d20d926Sriastradh * and/or sell copies of the Software, and to permit persons to whom the
119d20d926Sriastradh * Software is furnished to do so, subject to the following conditions:
129d20d926Sriastradh *
139d20d926Sriastradh * The above copyright notice and this permission notice shall be included in
149d20d926Sriastradh * all copies or substantial portions of the Software.
159d20d926Sriastradh *
169d20d926Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
179d20d926Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
189d20d926Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
199d20d926Sriastradh * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
209d20d926Sriastradh * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
219d20d926Sriastradh * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
229d20d926Sriastradh * OTHER DEALINGS IN THE SOFTWARE.
239d20d926Sriastradh *
249d20d926Sriastradh * Authors: Dave Airlie
259d20d926Sriastradh * Alon Levy
269d20d926Sriastradh */
279d20d926Sriastradh #ifndef QXL_OBJECT_H
289d20d926Sriastradh #define QXL_OBJECT_H
299d20d926Sriastradh
309d20d926Sriastradh #include "qxl_drv.h"
319d20d926Sriastradh
qxl_bo_reserve(struct qxl_bo * bo,bool no_wait)329d20d926Sriastradh static inline int qxl_bo_reserve(struct qxl_bo *bo, bool no_wait)
339d20d926Sriastradh {
349d20d926Sriastradh int r;
359d20d926Sriastradh
36*41ec0267Sriastradh r = ttm_bo_reserve(&bo->tbo, true, no_wait, NULL);
379d20d926Sriastradh if (unlikely(r != 0)) {
389d20d926Sriastradh if (r != -ERESTARTSYS) {
39*41ec0267Sriastradh struct drm_device *ddev = bo->tbo.base.dev;
40*41ec0267Sriastradh
41*41ec0267Sriastradh dev_err(ddev->dev, "%p reserve failed\n", bo);
429d20d926Sriastradh }
439d20d926Sriastradh return r;
449d20d926Sriastradh }
459d20d926Sriastradh return 0;
469d20d926Sriastradh }
479d20d926Sriastradh
qxl_bo_unreserve(struct qxl_bo * bo)489d20d926Sriastradh static inline void qxl_bo_unreserve(struct qxl_bo *bo)
499d20d926Sriastradh {
509d20d926Sriastradh ttm_bo_unreserve(&bo->tbo);
519d20d926Sriastradh }
529d20d926Sriastradh
qxl_bo_gpu_offset(struct qxl_bo * bo)539d20d926Sriastradh static inline u64 qxl_bo_gpu_offset(struct qxl_bo *bo)
549d20d926Sriastradh {
559d20d926Sriastradh return bo->tbo.offset;
569d20d926Sriastradh }
579d20d926Sriastradh
qxl_bo_size(struct qxl_bo * bo)589d20d926Sriastradh static inline unsigned long qxl_bo_size(struct qxl_bo *bo)
599d20d926Sriastradh {
609d20d926Sriastradh return bo->tbo.num_pages << PAGE_SHIFT;
619d20d926Sriastradh }
629d20d926Sriastradh
qxl_bo_mmap_offset(struct qxl_bo * bo)639d20d926Sriastradh static inline u64 qxl_bo_mmap_offset(struct qxl_bo *bo)
649d20d926Sriastradh {
65*41ec0267Sriastradh return drm_vma_node_offset_addr(&bo->tbo.base.vma_node);
669d20d926Sriastradh }
679d20d926Sriastradh
qxl_bo_wait(struct qxl_bo * bo,u32 * mem_type,bool no_wait)689d20d926Sriastradh static inline int qxl_bo_wait(struct qxl_bo *bo, u32 *mem_type,
699d20d926Sriastradh bool no_wait)
709d20d926Sriastradh {
719d20d926Sriastradh int r;
729d20d926Sriastradh
73*41ec0267Sriastradh r = ttm_bo_reserve(&bo->tbo, true, no_wait, NULL);
749d20d926Sriastradh if (unlikely(r != 0)) {
759d20d926Sriastradh if (r != -ERESTARTSYS) {
76*41ec0267Sriastradh struct drm_device *ddev = bo->tbo.base.dev;
77*41ec0267Sriastradh
78*41ec0267Sriastradh dev_err(ddev->dev, "%p reserve failed for wait\n",
799d20d926Sriastradh bo);
809d20d926Sriastradh }
819d20d926Sriastradh return r;
829d20d926Sriastradh }
839d20d926Sriastradh if (mem_type)
849d20d926Sriastradh *mem_type = bo->tbo.mem.mem_type;
85efa246c0Sriastradh
86*41ec0267Sriastradh r = ttm_bo_wait(&bo->tbo, true, no_wait);
879d20d926Sriastradh ttm_bo_unreserve(&bo->tbo);
889d20d926Sriastradh return r;
899d20d926Sriastradh }
909d20d926Sriastradh
919d20d926Sriastradh extern int qxl_bo_create(struct qxl_device *qdev,
929d20d926Sriastradh unsigned long size,
939d20d926Sriastradh bool kernel, bool pinned, u32 domain,
949d20d926Sriastradh struct qxl_surface *surf,
959d20d926Sriastradh struct qxl_bo **bo_ptr);
969d20d926Sriastradh extern int qxl_bo_kmap(struct qxl_bo *bo, void **ptr);
979d20d926Sriastradh extern void qxl_bo_kunmap(struct qxl_bo *bo);
989d20d926Sriastradh void *qxl_bo_kmap_atomic_page(struct qxl_device *qdev, struct qxl_bo *bo, int page_offset);
999d20d926Sriastradh void qxl_bo_kunmap_atomic_page(struct qxl_device *qdev, struct qxl_bo *bo, void *map);
1009d20d926Sriastradh extern struct qxl_bo *qxl_bo_ref(struct qxl_bo *bo);
1019d20d926Sriastradh extern void qxl_bo_unref(struct qxl_bo **bo);
102*41ec0267Sriastradh extern int qxl_bo_pin(struct qxl_bo *bo);
1039d20d926Sriastradh extern int qxl_bo_unpin(struct qxl_bo *bo);
1049d20d926Sriastradh extern void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain, bool pinned);
1059d20d926Sriastradh extern bool qxl_ttm_bo_is_qxl_bo(struct ttm_buffer_object *bo);
1069d20d926Sriastradh
1079d20d926Sriastradh #endif
108