amdgpu_internal.h revision 00a23bda
13f012e29Smrg/* 23f012e29Smrg * Copyright © 2014 Advanced Micro Devices, Inc. 33f012e29Smrg * All Rights Reserved. 43f012e29Smrg * 53f012e29Smrg * Permission is hereby granted, free of charge, to any person obtaining a 63f012e29Smrg * copy of this software and associated documentation files (the "Software"), 73f012e29Smrg * to deal in the Software without restriction, including without limitation 83f012e29Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 93f012e29Smrg * and/or sell copies of the Software, and to permit persons to whom the 103f012e29Smrg * Software is furnished to do so, subject to the following conditions: 113f012e29Smrg * 123f012e29Smrg * The above copyright notice and this permission notice shall be included in 133f012e29Smrg * all copies or substantial portions of the Software. 143f012e29Smrg * 153f012e29Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 163f012e29Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 173f012e29Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 183f012e29Smrg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 193f012e29Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 203f012e29Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 213f012e29Smrg * OTHER DEALINGS IN THE SOFTWARE. 223f012e29Smrg * 233f012e29Smrg */ 243f012e29Smrg 253f012e29Smrg#ifndef _AMDGPU_INTERNAL_H_ 263f012e29Smrg#define _AMDGPU_INTERNAL_H_ 273f012e29Smrg 283f012e29Smrg#ifdef HAVE_CONFIG_H 293f012e29Smrg#include "config.h" 303f012e29Smrg#endif 313f012e29Smrg 323f012e29Smrg#include <assert.h> 333f012e29Smrg#include <pthread.h> 343f012e29Smrg 353f012e29Smrg#include "libdrm_macros.h" 363f012e29Smrg#include "xf86atomic.h" 373f012e29Smrg#include "amdgpu.h" 383f012e29Smrg#include "util_double_list.h" 393f012e29Smrg 403f012e29Smrg#define AMDGPU_CS_MAX_RINGS 8 413f012e29Smrg/* do not use below macro if b is not power of 2 aligned value */ 423f012e29Smrg#define __round_mask(x, y) ((__typeof__(x))((y)-1)) 433f012e29Smrg#define ROUND_UP(x, y) ((((x)-1) | __round_mask(x, y))+1) 443f012e29Smrg#define ROUND_DOWN(x, y) ((x) & ~__round_mask(x, y)) 453f012e29Smrg 463f012e29Smrg#define AMDGPU_INVALID_VA_ADDRESS 0xffffffffffffffff 473f012e29Smrg#define AMDGPU_NULL_SUBMIT_SEQ 0 483f012e29Smrg 493f012e29Smrgstruct amdgpu_bo_va_hole { 503f012e29Smrg struct list_head list; 513f012e29Smrg uint64_t offset; 523f012e29Smrg uint64_t size; 533f012e29Smrg}; 543f012e29Smrg 553f012e29Smrgstruct amdgpu_bo_va_mgr { 563f012e29Smrg uint64_t va_max; 573f012e29Smrg struct list_head va_holes; 583f012e29Smrg pthread_mutex_t bo_va_mutex; 593f012e29Smrg uint32_t va_alignment; 603f012e29Smrg}; 613f012e29Smrg 623f012e29Smrgstruct amdgpu_va { 633f012e29Smrg amdgpu_device_handle dev; 643f012e29Smrg uint64_t address; 653f012e29Smrg uint64_t size; 663f012e29Smrg enum amdgpu_gpu_va_range range; 673f012e29Smrg struct amdgpu_bo_va_mgr *vamgr; 683f012e29Smrg}; 693f012e29Smrg 703f012e29Smrgstruct amdgpu_device { 713f012e29Smrg atomic_t refcount; 723f012e29Smrg int fd; 733f012e29Smrg int flink_fd; 743f012e29Smrg unsigned major_version; 753f012e29Smrg unsigned minor_version; 763f012e29Smrg 7700a23bdaSmrg char *marketing_name; 783f012e29Smrg /** List of buffer handles. Protected by bo_table_mutex. */ 793f012e29Smrg struct util_hash_table *bo_handles; 803f012e29Smrg /** List of buffer GEM flink names. Protected by bo_table_mutex. */ 813f012e29Smrg struct util_hash_table *bo_flink_names; 823f012e29Smrg /** This protects all hash tables. */ 833f012e29Smrg pthread_mutex_t bo_table_mutex; 843f012e29Smrg struct drm_amdgpu_info_device dev_info; 853f012e29Smrg struct amdgpu_gpu_info info; 8600a23bdaSmrg /** The VA manager for the lower virtual address space */ 87d8807b2fSmrg struct amdgpu_bo_va_mgr vamgr; 883f012e29Smrg /** The VA manager for the 32bit address space */ 89d8807b2fSmrg struct amdgpu_bo_va_mgr vamgr_32; 9000a23bdaSmrg /** The VA manager for the high virtual address space */ 9100a23bdaSmrg struct amdgpu_bo_va_mgr vamgr_high; 9200a23bdaSmrg /** The VA manager for the 32bit high address space */ 9300a23bdaSmrg struct amdgpu_bo_va_mgr vamgr_high_32; 943f012e29Smrg}; 953f012e29Smrg 963f012e29Smrgstruct amdgpu_bo { 973f012e29Smrg atomic_t refcount; 983f012e29Smrg struct amdgpu_device *dev; 993f012e29Smrg 1003f012e29Smrg uint64_t alloc_size; 1013f012e29Smrg 1023f012e29Smrg uint32_t handle; 1033f012e29Smrg uint32_t flink_name; 1043f012e29Smrg 1053f012e29Smrg pthread_mutex_t cpu_access_mutex; 1063f012e29Smrg void *cpu_ptr; 1073f012e29Smrg int cpu_map_count; 1083f012e29Smrg}; 1093f012e29Smrg 1103f012e29Smrgstruct amdgpu_bo_list { 1113f012e29Smrg struct amdgpu_device *dev; 1123f012e29Smrg 1133f012e29Smrg uint32_t handle; 1143f012e29Smrg}; 1153f012e29Smrg 1163f012e29Smrgstruct amdgpu_context { 1173f012e29Smrg struct amdgpu_device *dev; 1183f012e29Smrg /** Mutex for accessing fences and to maintain command submissions 1193f012e29Smrg in good sequence. */ 1203f012e29Smrg pthread_mutex_t sequence_mutex; 1213f012e29Smrg /* context id*/ 1223f012e29Smrg uint32_t id; 1233f012e29Smrg uint64_t last_seq[AMDGPU_HW_IP_NUM][AMDGPU_HW_IP_INSTANCE_MAX_COUNT][AMDGPU_CS_MAX_RINGS]; 1243f012e29Smrg struct list_head sem_list[AMDGPU_HW_IP_NUM][AMDGPU_HW_IP_INSTANCE_MAX_COUNT][AMDGPU_CS_MAX_RINGS]; 1253f012e29Smrg}; 1263f012e29Smrg 1273f012e29Smrg/** 1283f012e29Smrg * Structure describing sw semaphore based on scheduler 1293f012e29Smrg * 1303f012e29Smrg */ 1313f012e29Smrgstruct amdgpu_semaphore { 1323f012e29Smrg atomic_t refcount; 1333f012e29Smrg struct list_head list; 1343f012e29Smrg struct amdgpu_cs_fence signal_fence; 1353f012e29Smrg}; 1363f012e29Smrg 1373f012e29Smrg/** 1383f012e29Smrg * Functions. 1393f012e29Smrg */ 1403f012e29Smrg 1413f012e29Smrgdrm_private void amdgpu_vamgr_init(struct amdgpu_bo_va_mgr *mgr, uint64_t start, 1423f012e29Smrg uint64_t max, uint64_t alignment); 1433f012e29Smrg 1443f012e29Smrgdrm_private void amdgpu_vamgr_deinit(struct amdgpu_bo_va_mgr *mgr); 1453f012e29Smrg 14600a23bdaSmrgdrm_private void amdgpu_parse_asic_ids(struct amdgpu_device *dev); 147d8807b2fSmrg 1483f012e29Smrgdrm_private int amdgpu_query_gpu_info_init(amdgpu_device_handle dev); 1493f012e29Smrg 1503f012e29Smrgdrm_private uint64_t amdgpu_cs_calculate_timeout(uint64_t timeout); 1513f012e29Smrg 1523f012e29Smrg/** 1533f012e29Smrg * Inline functions. 1543f012e29Smrg */ 1553f012e29Smrg 1563f012e29Smrg/** 1573f012e29Smrg * Increment src and decrement dst as if we were updating references 1583f012e29Smrg * for an assignment between 2 pointers of some objects. 1593f012e29Smrg * 1603f012e29Smrg * \return true if dst is 0 1613f012e29Smrg */ 1623f012e29Smrgstatic inline bool update_references(atomic_t *dst, atomic_t *src) 1633f012e29Smrg{ 1643f012e29Smrg if (dst != src) { 1653f012e29Smrg /* bump src first */ 1663f012e29Smrg if (src) { 1673f012e29Smrg assert(atomic_read(src) > 0); 1683f012e29Smrg atomic_inc(src); 1693f012e29Smrg } 1703f012e29Smrg if (dst) { 1713f012e29Smrg assert(atomic_read(dst) > 0); 1723f012e29Smrg return atomic_dec_and_test(dst); 1733f012e29Smrg } 1743f012e29Smrg } 1753f012e29Smrg return false; 1763f012e29Smrg} 1773f012e29Smrg 1783f012e29Smrg#endif 179