radeon_bo.c revision e6188e58
122944501Smrg/* 222944501Smrg * Copyright © 2008 Dave Airlie 322944501Smrg * Copyright © 2008 Jérôme Glisse 422944501Smrg * All Rights Reserved. 522944501Smrg * 622944501Smrg * Permission is hereby granted, free of charge, to any person obtaining 722944501Smrg * a copy of this software and associated documentation files (the 822944501Smrg * "Software"), to deal in the Software without restriction, including 922944501Smrg * without limitation the rights to use, copy, modify, merge, publish, 1022944501Smrg * distribute, sub license, and/or sell copies of the Software, and to 1122944501Smrg * permit persons to whom the Software is furnished to do so, subject to 1222944501Smrg * the following conditions: 1322944501Smrg * 1422944501Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 1522944501Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 1622944501Smrg * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 1722944501Smrg * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS 1822944501Smrg * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1922944501Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 2022944501Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 2122944501Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 2222944501Smrg * 2322944501Smrg * The above copyright notice and this permission notice (including the 2422944501Smrg * next paragraph) shall be included in all copies or substantial portions 2522944501Smrg * of the Software. 2622944501Smrg */ 2722944501Smrg/* 2822944501Smrg * Authors: 2922944501Smrg * Dave Airlie 3022944501Smrg * Jérôme Glisse <glisse@freedesktop.org> 3122944501Smrg */ 32baaff307Smrg#ifdef HAVE_CONFIG_H 33baaff307Smrg#include <config.h> 34baaff307Smrg#endif 35e6188e58Smrg#include <libdrm_macros.h> 3622944501Smrg#include <radeon_bo.h> 3722944501Smrg#include <radeon_bo_int.h> 3822944501Smrg 39e6188e58Smrgvoid radeon_bo_debug(struct radeon_bo *bo, const char *op) 4022944501Smrg{ 4122944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 4222944501Smrg 4322944501Smrg fprintf(stderr, "%s %p 0x%08X 0x%08X 0x%08X\n", 4422944501Smrg op, bo, bo->handle, boi->size, boi->cref); 4522944501Smrg} 4622944501Smrg 47e6188e58Smrgstruct radeon_bo * 48baaff307Smrgradeon_bo_open(struct radeon_bo_manager *bom, uint32_t handle, uint32_t size, 49baaff307Smrg uint32_t alignment, uint32_t domains, uint32_t flags) 5022944501Smrg{ 5122944501Smrg struct radeon_bo *bo; 5222944501Smrg bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags); 5322944501Smrg return bo; 5422944501Smrg} 5522944501Smrg 56e6188e58Smrgvoid radeon_bo_ref(struct radeon_bo *bo) 5722944501Smrg{ 5822944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 5922944501Smrg boi->cref++; 6022944501Smrg boi->bom->funcs->bo_ref(boi); 6122944501Smrg} 6222944501Smrg 63e6188e58Smrgstruct radeon_bo *radeon_bo_unref(struct radeon_bo *bo) 6422944501Smrg{ 6522944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 6622944501Smrg if (bo == NULL) 6722944501Smrg return NULL; 6822944501Smrg 6922944501Smrg boi->cref--; 7022944501Smrg return boi->bom->funcs->bo_unref(boi); 7122944501Smrg} 7222944501Smrg 73e6188e58Smrgint radeon_bo_map(struct radeon_bo *bo, int write) 7422944501Smrg{ 7522944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 7622944501Smrg return boi->bom->funcs->bo_map(boi, write); 7722944501Smrg} 7822944501Smrg 79e6188e58Smrgint radeon_bo_unmap(struct radeon_bo *bo) 8022944501Smrg{ 8122944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 8222944501Smrg return boi->bom->funcs->bo_unmap(boi); 8322944501Smrg} 8422944501Smrg 85e6188e58Smrgint radeon_bo_wait(struct radeon_bo *bo) 8622944501Smrg{ 8722944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 8822944501Smrg if (!boi->bom->funcs->bo_wait) 8922944501Smrg return 0; 9022944501Smrg return boi->bom->funcs->bo_wait(boi); 9122944501Smrg} 9222944501Smrg 93e6188e58Smrgint radeon_bo_is_busy(struct radeon_bo *bo, uint32_t *domain) 9422944501Smrg{ 9522944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 9622944501Smrg return boi->bom->funcs->bo_is_busy(boi, domain); 9722944501Smrg} 9822944501Smrg 99e6188e58Smrgint 100baaff307Smrgradeon_bo_set_tiling(struct radeon_bo *bo, 101baaff307Smrg uint32_t tiling_flags, uint32_t pitch) 10222944501Smrg{ 10322944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 10422944501Smrg return boi->bom->funcs->bo_set_tiling(boi, tiling_flags, pitch); 10522944501Smrg} 10622944501Smrg 107e6188e58Smrgint 108baaff307Smrgradeon_bo_get_tiling(struct radeon_bo *bo, 109baaff307Smrg uint32_t *tiling_flags, uint32_t *pitch) 11022944501Smrg{ 11122944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 11222944501Smrg return boi->bom->funcs->bo_get_tiling(boi, tiling_flags, pitch); 11322944501Smrg} 11422944501Smrg 115e6188e58Smrgint radeon_bo_is_static(struct radeon_bo *bo) 11622944501Smrg{ 11722944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 11822944501Smrg if (boi->bom->funcs->bo_is_static) 11922944501Smrg return boi->bom->funcs->bo_is_static(boi); 12022944501Smrg return 0; 12122944501Smrg} 12222944501Smrg 123e6188e58Smrgint 124baaff307Smrgradeon_bo_is_referenced_by_cs(struct radeon_bo *bo, struct radeon_cs *cs) 12522944501Smrg{ 12622944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 12722944501Smrg return boi->cref > 1; 12822944501Smrg} 12922944501Smrg 130e6188e58Smrguint32_t radeon_bo_get_handle(struct radeon_bo *bo) 13122944501Smrg{ 13222944501Smrg return bo->handle; 13322944501Smrg} 13422944501Smrg 135e6188e58Smrguint32_t radeon_bo_get_src_domain(struct radeon_bo *bo) 13622944501Smrg{ 13722944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 13822944501Smrg uint32_t src_domain; 13922944501Smrg 14022944501Smrg src_domain = boi->space_accounted & 0xffff; 14122944501Smrg if (!src_domain) 14222944501Smrg src_domain = boi->space_accounted >> 16; 14322944501Smrg 14422944501Smrg return src_domain; 14522944501Smrg} 146