Back to index

libdrm  2.4.37
radeon_bo.c
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2008 Dave Airlie
00003  * Copyright © 2008 Jérôme Glisse
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining
00007  * a copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00015  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00016  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00017  * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
00018  * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00020  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
00021  * USE OR OTHER DEALINGS IN THE SOFTWARE.
00022  *
00023  * The above copyright notice and this permission notice (including the
00024  * next paragraph) shall be included in all copies or substantial portions
00025  * of the Software.
00026  */
00027 /*
00028  * Authors:
00029  *      Dave Airlie
00030  *      Jérôme Glisse <glisse@freedesktop.org>
00031  */
00032 #include <radeon_bo.h>
00033 #include <radeon_bo_int.h>
00034 
00035 void radeon_bo_debug(struct radeon_bo *bo, const char *op)
00036 {
00037     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00038 
00039     fprintf(stderr, "%s %p 0x%08X 0x%08X 0x%08X\n",
00040             op, bo, bo->handle, boi->size, boi->cref);
00041 }
00042 
00043 struct radeon_bo *radeon_bo_open(struct radeon_bo_manager *bom,
00044                                  uint32_t handle,
00045                                  uint32_t size,
00046                                  uint32_t alignment,
00047                                  uint32_t domains,
00048                                  uint32_t flags)
00049 {
00050     struct radeon_bo *bo;
00051     bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags);
00052     return bo;
00053 }
00054 
00055 void radeon_bo_ref(struct radeon_bo *bo)
00056 {
00057     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00058     boi->cref++;
00059     boi->bom->funcs->bo_ref(boi);
00060 }
00061 
00062 struct radeon_bo *radeon_bo_unref(struct radeon_bo *bo)
00063 {
00064     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00065     if (bo == NULL)
00066         return NULL;
00067 
00068     boi->cref--;
00069     return boi->bom->funcs->bo_unref(boi);
00070 }
00071 
00072 int radeon_bo_map(struct radeon_bo *bo, int write)
00073 {
00074     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00075     return boi->bom->funcs->bo_map(boi, write);
00076 }
00077 
00078 int radeon_bo_unmap(struct radeon_bo *bo)
00079 {
00080     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00081     return boi->bom->funcs->bo_unmap(boi);
00082 }
00083 
00084 int radeon_bo_wait(struct radeon_bo *bo)
00085 {
00086     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00087     if (!boi->bom->funcs->bo_wait)
00088         return 0;
00089     return boi->bom->funcs->bo_wait(boi);
00090 }
00091 
00092 int radeon_bo_is_busy(struct radeon_bo *bo, uint32_t *domain)
00093 {
00094     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00095     return boi->bom->funcs->bo_is_busy(boi, domain);
00096 }
00097 
00098 int radeon_bo_set_tiling(struct radeon_bo *bo,
00099                          uint32_t tiling_flags, uint32_t pitch)
00100 {
00101     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00102     return boi->bom->funcs->bo_set_tiling(boi, tiling_flags, pitch);
00103 }
00104 
00105 int radeon_bo_get_tiling(struct radeon_bo *bo,
00106                          uint32_t *tiling_flags, uint32_t *pitch)
00107 {
00108     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00109     return boi->bom->funcs->bo_get_tiling(boi, tiling_flags, pitch);
00110 }
00111 
00112 int radeon_bo_is_static(struct radeon_bo *bo)
00113 {
00114     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00115     if (boi->bom->funcs->bo_is_static)
00116         return boi->bom->funcs->bo_is_static(boi);
00117     return 0;
00118 }
00119 
00120 int radeon_bo_is_referenced_by_cs(struct radeon_bo *bo, struct radeon_cs *cs)
00121 {
00122     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00123     return boi->cref > 1;
00124 }
00125 
00126 uint32_t radeon_bo_get_handle(struct radeon_bo *bo)
00127 {
00128     return bo->handle;
00129 }
00130 
00131 uint32_t radeon_bo_get_src_domain(struct radeon_bo *bo)
00132 {
00133     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
00134     uint32_t src_domain;
00135 
00136     src_domain = boi->space_accounted & 0xffff;
00137     if (!src_domain)
00138         src_domain = boi->space_accounted >> 16;
00139 
00140     return src_domain;
00141 }