1254885Sdumbbell/* 2254885Sdumbbell * Copyright 2008 Advanced Micro Devices, Inc. 3254885Sdumbbell * Copyright 2008 Red Hat Inc. 4254885Sdumbbell * Copyright 2009 Jerome Glisse. 5254885Sdumbbell * 6254885Sdumbbell * Permission is hereby granted, free of charge, to any person obtaining a 7254885Sdumbbell * copy of this software and associated documentation files (the "Software"), 8254885Sdumbbell * to deal in the Software without restriction, including without limitation 9254885Sdumbbell * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10254885Sdumbbell * and/or sell copies of the Software, and to permit persons to whom the 11254885Sdumbbell * Software is furnished to do so, subject to the following conditions: 12254885Sdumbbell * 13254885Sdumbbell * The above copyright notice and this permission notice shall be included in 14254885Sdumbbell * all copies or substantial portions of the Software. 15254885Sdumbbell * 16254885Sdumbbell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17254885Sdumbbell * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18254885Sdumbbell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19254885Sdumbbell * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20254885Sdumbbell * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21254885Sdumbbell * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22254885Sdumbbell * OTHER DEALINGS IN THE SOFTWARE. 23254885Sdumbbell * 24254885Sdumbbell * Authors: Dave Airlie 25254885Sdumbbell * Alex Deucher 26254885Sdumbbell * Jerome Glisse 27254885Sdumbbell */ 28254885Sdumbbell 29254885Sdumbbell#include <sys/cdefs.h> 30254885Sdumbbell__FBSDID("$FreeBSD$"); 31254885Sdumbbell 32254885Sdumbbell#ifndef __RADEON_OBJECT_H__ 33254885Sdumbbell#define __RADEON_OBJECT_H__ 34254885Sdumbbell 35254885Sdumbbell#include <dev/drm2/radeon/radeon_drm.h> 36254885Sdumbbell#include "radeon.h" 37254885Sdumbbell 38254885Sdumbbell/* 39254885Sdumbbell * Undefine max_offset (defined in vm/vm_map.h), because it conflicts 40254885Sdumbbell * with an argument of the function radeon_bo_pin_restricted(). 41254885Sdumbbell */ 42254885Sdumbbell#undef max_offset 43254885Sdumbbell 44254885Sdumbbell/** 45254885Sdumbbell * radeon_mem_type_to_domain - return domain corresponding to mem_type 46254885Sdumbbell * @mem_type: ttm memory type 47254885Sdumbbell * 48254885Sdumbbell * Returns corresponding domain of the ttm mem_type 49254885Sdumbbell */ 50254885Sdumbbellstatic inline unsigned radeon_mem_type_to_domain(u32 mem_type) 51254885Sdumbbell{ 52254885Sdumbbell switch (mem_type) { 53254885Sdumbbell case TTM_PL_VRAM: 54254885Sdumbbell return RADEON_GEM_DOMAIN_VRAM; 55254885Sdumbbell case TTM_PL_TT: 56254885Sdumbbell return RADEON_GEM_DOMAIN_GTT; 57254885Sdumbbell case TTM_PL_SYSTEM: 58254885Sdumbbell return RADEON_GEM_DOMAIN_CPU; 59254885Sdumbbell default: 60254885Sdumbbell break; 61254885Sdumbbell } 62254885Sdumbbell return 0; 63254885Sdumbbell} 64254885Sdumbbell 65254885Sdumbbellint radeon_bo_reserve(struct radeon_bo *bo, bool no_intr); 66254885Sdumbbell 67254885Sdumbbellstatic inline void radeon_bo_unreserve(struct radeon_bo *bo) 68254885Sdumbbell{ 69254885Sdumbbell ttm_bo_unreserve(&bo->tbo); 70254885Sdumbbell} 71254885Sdumbbell 72254885Sdumbbell/** 73254885Sdumbbell * radeon_bo_gpu_offset - return GPU offset of bo 74254885Sdumbbell * @bo: radeon object for which we query the offset 75254885Sdumbbell * 76254885Sdumbbell * Returns current GPU offset of the object. 77254885Sdumbbell * 78254885Sdumbbell * Note: object should either be pinned or reserved when calling this 79254885Sdumbbell * function, it might be useful to add check for this for debugging. 80254885Sdumbbell */ 81254885Sdumbbellstatic inline u64 radeon_bo_gpu_offset(struct radeon_bo *bo) 82254885Sdumbbell{ 83254885Sdumbbell return bo->tbo.offset; 84254885Sdumbbell} 85254885Sdumbbell 86254885Sdumbbellstatic inline unsigned long radeon_bo_size(struct radeon_bo *bo) 87254885Sdumbbell{ 88254885Sdumbbell return bo->tbo.num_pages << PAGE_SHIFT; 89254885Sdumbbell} 90254885Sdumbbell 91254885Sdumbbellstatic inline bool radeon_bo_is_reserved(struct radeon_bo *bo) 92254885Sdumbbell{ 93254885Sdumbbell return ttm_bo_is_reserved(&bo->tbo); 94254885Sdumbbell} 95254885Sdumbbell 96254885Sdumbbellstatic inline unsigned radeon_bo_ngpu_pages(struct radeon_bo *bo) 97254885Sdumbbell{ 98254885Sdumbbell return (bo->tbo.num_pages << PAGE_SHIFT) / RADEON_GPU_PAGE_SIZE; 99254885Sdumbbell} 100254885Sdumbbell 101254885Sdumbbellstatic inline unsigned radeon_bo_gpu_page_alignment(struct radeon_bo *bo) 102254885Sdumbbell{ 103254885Sdumbbell return (bo->tbo.mem.page_alignment << PAGE_SHIFT) / RADEON_GPU_PAGE_SIZE; 104254885Sdumbbell} 105254885Sdumbbell 106254885Sdumbbell/** 107254885Sdumbbell * radeon_bo_mmap_offset - return mmap offset of bo 108254885Sdumbbell * @bo: radeon object for which we query the offset 109254885Sdumbbell * 110254885Sdumbbell * Returns mmap offset of the object. 111254885Sdumbbell * 112254885Sdumbbell * Note: addr_space_offset is constant after ttm bo init thus isn't protected 113254885Sdumbbell * by any lock. 114254885Sdumbbell */ 115254885Sdumbbellstatic inline u64 radeon_bo_mmap_offset(struct radeon_bo *bo) 116254885Sdumbbell{ 117254885Sdumbbell return bo->tbo.addr_space_offset; 118254885Sdumbbell} 119254885Sdumbbell 120254885Sdumbbellextern int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type, 121254885Sdumbbell bool no_wait); 122254885Sdumbbell 123254885Sdumbbellextern int radeon_bo_create(struct radeon_device *rdev, 124254885Sdumbbell unsigned long size, int byte_align, 125254885Sdumbbell bool kernel, u32 domain, 126254885Sdumbbell struct sg_table *sg, 127254885Sdumbbell struct radeon_bo **bo_ptr); 128254885Sdumbbellextern int radeon_bo_kmap(struct radeon_bo *bo, void **ptr); 129254885Sdumbbellextern void radeon_bo_kunmap(struct radeon_bo *bo); 130254885Sdumbbellextern void radeon_bo_unref(struct radeon_bo **bo); 131254885Sdumbbellextern int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr); 132254885Sdumbbellextern int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, 133254885Sdumbbell u64 max_offset, u64 *gpu_addr); 134254885Sdumbbellextern int radeon_bo_unpin(struct radeon_bo *bo); 135254885Sdumbbellextern int radeon_bo_evict_vram(struct radeon_device *rdev); 136254885Sdumbbellextern void radeon_bo_force_delete(struct radeon_device *rdev); 137254885Sdumbbellextern int radeon_bo_init(struct radeon_device *rdev); 138254885Sdumbbellextern void radeon_bo_fini(struct radeon_device *rdev); 139254885Sdumbbellextern void radeon_bo_list_add_object(struct radeon_bo_list *lobj, 140254885Sdumbbell struct list_head *head); 141254885Sdumbbellextern int radeon_bo_list_validate(struct list_head *head); 142254885Sdumbbell#ifdef DUMBBELL_WIP 143254885Sdumbbellextern int radeon_bo_fbdev_mmap(struct radeon_bo *bo, 144254885Sdumbbell struct vm_area_struct *vma); 145254885Sdumbbell#endif /* DUMBBELL_WIP */ 146254885Sdumbbellextern int radeon_bo_set_tiling_flags(struct radeon_bo *bo, 147254885Sdumbbell u32 tiling_flags, u32 pitch); 148254885Sdumbbellextern void radeon_bo_get_tiling_flags(struct radeon_bo *bo, 149254885Sdumbbell u32 *tiling_flags, u32 *pitch); 150254885Sdumbbellextern int radeon_bo_check_tiling(struct radeon_bo *bo, bool has_moved, 151254885Sdumbbell bool force_drop); 152254885Sdumbbellextern void radeon_bo_move_notify(struct ttm_buffer_object *bo, 153254885Sdumbbell struct ttm_mem_reg *mem); 154254885Sdumbbellextern int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo); 155254885Sdumbbellextern int radeon_bo_get_surface_reg(struct radeon_bo *bo); 156254885Sdumbbell 157254885Sdumbbell/* 158254885Sdumbbell * sub allocation 159254885Sdumbbell */ 160254885Sdumbbell 161254885Sdumbbellstatic inline uint64_t radeon_sa_bo_gpu_addr(struct radeon_sa_bo *sa_bo) 162254885Sdumbbell{ 163254885Sdumbbell return sa_bo->manager->gpu_addr + sa_bo->soffset; 164254885Sdumbbell} 165254885Sdumbbell 166254885Sdumbbellstatic inline void * radeon_sa_bo_cpu_addr(struct radeon_sa_bo *sa_bo) 167254885Sdumbbell{ 168254885Sdumbbell return (char *)sa_bo->manager->cpu_ptr + sa_bo->soffset; 169254885Sdumbbell} 170254885Sdumbbell 171254885Sdumbbellextern int radeon_sa_bo_manager_init(struct radeon_device *rdev, 172254885Sdumbbell struct radeon_sa_manager *sa_manager, 173254885Sdumbbell unsigned size, u32 domain); 174254885Sdumbbellextern void radeon_sa_bo_manager_fini(struct radeon_device *rdev, 175254885Sdumbbell struct radeon_sa_manager *sa_manager); 176254885Sdumbbellextern int radeon_sa_bo_manager_start(struct radeon_device *rdev, 177254885Sdumbbell struct radeon_sa_manager *sa_manager); 178254885Sdumbbellextern int radeon_sa_bo_manager_suspend(struct radeon_device *rdev, 179254885Sdumbbell struct radeon_sa_manager *sa_manager); 180254885Sdumbbellextern int radeon_sa_bo_new(struct radeon_device *rdev, 181254885Sdumbbell struct radeon_sa_manager *sa_manager, 182254885Sdumbbell struct radeon_sa_bo **sa_bo, 183254885Sdumbbell unsigned size, unsigned align, bool block); 184254885Sdumbbellextern void radeon_sa_bo_free(struct radeon_device *rdev, 185254885Sdumbbell struct radeon_sa_bo **sa_bo, 186254885Sdumbbell struct radeon_fence *fence); 187254885Sdumbbell#if defined(CONFIG_DEBUG_FS) 188254885Sdumbbellextern void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager, 189254885Sdumbbell struct seq_file *m); 190254885Sdumbbell#endif 191254885Sdumbbell 192254885Sdumbbell 193254885Sdumbbell#endif 194