radeon_bo.c revision 22944501
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 */ 3222944501Smrg#include <radeon_bo.h> 3322944501Smrg#include <radeon_bo_int.h> 3422944501Smrg 3522944501Smrgvoid radeon_bo_debug(struct radeon_bo *bo, const char *op) 3622944501Smrg{ 3722944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 3822944501Smrg 3922944501Smrg fprintf(stderr, "%s %p 0x%08X 0x%08X 0x%08X\n", 4022944501Smrg op, bo, bo->handle, boi->size, boi->cref); 4122944501Smrg} 4222944501Smrg 4322944501Smrgstruct radeon_bo *radeon_bo_open(struct radeon_bo_manager *bom, 4422944501Smrg uint32_t handle, 4522944501Smrg uint32_t size, 4622944501Smrg uint32_t alignment, 4722944501Smrg uint32_t domains, 4822944501Smrg uint32_t flags) 4922944501Smrg{ 5022944501Smrg struct radeon_bo *bo; 5122944501Smrg bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags); 5222944501Smrg return bo; 5322944501Smrg} 5422944501Smrg 5522944501Smrgvoid radeon_bo_ref(struct radeon_bo *bo) 5622944501Smrg{ 5722944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 5822944501Smrg boi->cref++; 5922944501Smrg boi->bom->funcs->bo_ref(boi); 6022944501Smrg} 6122944501Smrg 6222944501Smrgstruct radeon_bo *radeon_bo_unref(struct radeon_bo *bo) 6322944501Smrg{ 6422944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 6522944501Smrg if (bo == NULL) 6622944501Smrg return NULL; 6722944501Smrg 6822944501Smrg boi->cref--; 6922944501Smrg return boi->bom->funcs->bo_unref(boi); 7022944501Smrg} 7122944501Smrg 7222944501Smrgint radeon_bo_map(struct radeon_bo *bo, int write) 7322944501Smrg{ 7422944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 7522944501Smrg return boi->bom->funcs->bo_map(boi, write); 7622944501Smrg} 7722944501Smrg 7822944501Smrgint radeon_bo_unmap(struct radeon_bo *bo) 7922944501Smrg{ 8022944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 8122944501Smrg return boi->bom->funcs->bo_unmap(boi); 8222944501Smrg} 8322944501Smrg 8422944501Smrgint radeon_bo_wait(struct radeon_bo *bo) 8522944501Smrg{ 8622944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 8722944501Smrg if (!boi->bom->funcs->bo_wait) 8822944501Smrg return 0; 8922944501Smrg return boi->bom->funcs->bo_wait(boi); 9022944501Smrg} 9122944501Smrg 9222944501Smrgint radeon_bo_is_busy(struct radeon_bo *bo, uint32_t *domain) 9322944501Smrg{ 9422944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 9522944501Smrg return boi->bom->funcs->bo_is_busy(boi, domain); 9622944501Smrg} 9722944501Smrg 9822944501Smrgint radeon_bo_set_tiling(struct radeon_bo *bo, 9922944501Smrg uint32_t tiling_flags, uint32_t pitch) 10022944501Smrg{ 10122944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 10222944501Smrg return boi->bom->funcs->bo_set_tiling(boi, tiling_flags, pitch); 10322944501Smrg} 10422944501Smrg 10522944501Smrgint radeon_bo_get_tiling(struct radeon_bo *bo, 10622944501Smrg uint32_t *tiling_flags, uint32_t *pitch) 10722944501Smrg{ 10822944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 10922944501Smrg return boi->bom->funcs->bo_get_tiling(boi, tiling_flags, pitch); 11022944501Smrg} 11122944501Smrg 11222944501Smrgint radeon_bo_is_static(struct radeon_bo *bo) 11322944501Smrg{ 11422944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 11522944501Smrg if (boi->bom->funcs->bo_is_static) 11622944501Smrg return boi->bom->funcs->bo_is_static(boi); 11722944501Smrg return 0; 11822944501Smrg} 11922944501Smrg 12022944501Smrgint radeon_bo_is_referenced_by_cs(struct radeon_bo *bo, struct radeon_cs *cs) 12122944501Smrg{ 12222944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 12322944501Smrg return boi->cref > 1; 12422944501Smrg} 12522944501Smrg 12622944501Smrguint32_t radeon_bo_get_handle(struct radeon_bo *bo) 12722944501Smrg{ 12822944501Smrg return bo->handle; 12922944501Smrg} 13022944501Smrg 13122944501Smrguint32_t radeon_bo_get_src_domain(struct radeon_bo *bo) 13222944501Smrg{ 13322944501Smrg struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; 13422944501Smrg uint32_t src_domain; 13522944501Smrg 13622944501Smrg src_domain = boi->space_accounted & 0xffff; 13722944501Smrg if (!src_domain) 13822944501Smrg src_domain = boi->space_accounted >> 16; 13922944501Smrg 14022944501Smrg return src_domain; 14122944501Smrg} 142