amdgpu_internal.h revision bbff01ce
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#include <assert.h> 293f012e29Smrg#include <pthread.h> 303f012e29Smrg 313f012e29Smrg#include "libdrm_macros.h" 323f012e29Smrg#include "xf86atomic.h" 333f012e29Smrg#include "amdgpu.h" 343f012e29Smrg#include "util_double_list.h" 357cdc0497Smrg#include "handle_table.h" 363f012e29Smrg 373f012e29Smrg#define AMDGPU_CS_MAX_RINGS 8 383f012e29Smrg/* do not use below macro if b is not power of 2 aligned value */ 393f012e29Smrg#define __round_mask(x, y) ((__typeof__(x))((y)-1)) 403f012e29Smrg#define ROUND_UP(x, y) ((((x)-1) | __round_mask(x, y))+1) 413f012e29Smrg#define ROUND_DOWN(x, y) ((x) & ~__round_mask(x, y)) 423f012e29Smrg 433f012e29Smrg#define AMDGPU_INVALID_VA_ADDRESS 0xffffffffffffffff 443f012e29Smrg#define AMDGPU_NULL_SUBMIT_SEQ 0 453f012e29Smrg 463f012e29Smrgstruct amdgpu_bo_va_hole { 473f012e29Smrg struct list_head list; 483f012e29Smrg uint64_t offset; 493f012e29Smrg uint64_t size; 503f012e29Smrg}; 513f012e29Smrg 523f012e29Smrgstruct amdgpu_bo_va_mgr { 533f012e29Smrg uint64_t va_max; 543f012e29Smrg struct list_head va_holes; 553f012e29Smrg pthread_mutex_t bo_va_mutex; 563f012e29Smrg uint32_t va_alignment; 573f012e29Smrg}; 583f012e29Smrg 593f012e29Smrgstruct amdgpu_va { 603f012e29Smrg uint64_t address; 613f012e29Smrg uint64_t size; 623f012e29Smrg enum amdgpu_gpu_va_range range; 633f012e29Smrg struct amdgpu_bo_va_mgr *vamgr; 643f012e29Smrg}; 653f012e29Smrg 66bbff01ceSmrgstruct amdgpu_va_manager { 67bbff01ceSmrg /** The VA manager for the lower virtual address space */ 68bbff01ceSmrg struct amdgpu_bo_va_mgr vamgr_low; 69bbff01ceSmrg /** The VA manager for the 32bit address space */ 70bbff01ceSmrg struct amdgpu_bo_va_mgr vamgr_32; 71bbff01ceSmrg /** The VA manager for the high virtual address space */ 72bbff01ceSmrg struct amdgpu_bo_va_mgr vamgr_high; 73bbff01ceSmrg /** The VA manager for the 32bit high address space */ 74bbff01ceSmrg struct amdgpu_bo_va_mgr vamgr_high_32; 75bbff01ceSmrg}; 76bbff01ceSmrg 773f012e29Smrgstruct amdgpu_device { 783f012e29Smrg atomic_t refcount; 797cdc0497Smrg struct amdgpu_device *next; 803f012e29Smrg int fd; 813f012e29Smrg int flink_fd; 823f012e29Smrg unsigned major_version; 833f012e29Smrg unsigned minor_version; 843f012e29Smrg 8500a23bdaSmrg char *marketing_name; 863f012e29Smrg /** List of buffer handles. Protected by bo_table_mutex. */ 877cdc0497Smrg struct handle_table bo_handles; 883f012e29Smrg /** List of buffer GEM flink names. Protected by bo_table_mutex. */ 897cdc0497Smrg struct handle_table bo_flink_names; 903f012e29Smrg /** This protects all hash tables. */ 913f012e29Smrg pthread_mutex_t bo_table_mutex; 923f012e29Smrg struct drm_amdgpu_info_device dev_info; 933f012e29Smrg struct amdgpu_gpu_info info; 94bbff01ceSmrg 95bbff01ceSmrg struct amdgpu_va_manager va_mgr; 963f012e29Smrg}; 973f012e29Smrg 983f012e29Smrgstruct amdgpu_bo { 993f012e29Smrg atomic_t refcount; 1003f012e29Smrg struct amdgpu_device *dev; 1013f012e29Smrg 1023f012e29Smrg uint64_t alloc_size; 1033f012e29Smrg 1043f012e29Smrg uint32_t handle; 1053f012e29Smrg uint32_t flink_name; 1063f012e29Smrg 1073f012e29Smrg pthread_mutex_t cpu_access_mutex; 1083f012e29Smrg void *cpu_ptr; 1099bd392adSmrg int64_t cpu_map_count; 1103f012e29Smrg}; 1113f012e29Smrg 1123f012e29Smrgstruct amdgpu_bo_list { 1133f012e29Smrg struct amdgpu_device *dev; 1143f012e29Smrg 1153f012e29Smrg uint32_t handle; 1163f012e29Smrg}; 1173f012e29Smrg 1183f012e29Smrgstruct amdgpu_context { 1193f012e29Smrg struct amdgpu_device *dev; 1203f012e29Smrg /** Mutex for accessing fences and to maintain command submissions 1213f012e29Smrg in good sequence. */ 1223f012e29Smrg pthread_mutex_t sequence_mutex; 1233f012e29Smrg /* context id*/ 1243f012e29Smrg uint32_t id; 1253f012e29Smrg uint64_t last_seq[AMDGPU_HW_IP_NUM][AMDGPU_HW_IP_INSTANCE_MAX_COUNT][AMDGPU_CS_MAX_RINGS]; 1263f012e29Smrg struct list_head sem_list[AMDGPU_HW_IP_NUM][AMDGPU_HW_IP_INSTANCE_MAX_COUNT][AMDGPU_CS_MAX_RINGS]; 1273f012e29Smrg}; 1283f012e29Smrg 1293f012e29Smrg/** 1303f012e29Smrg * Structure describing sw semaphore based on scheduler 1313f012e29Smrg * 1323f012e29Smrg */ 1333f012e29Smrgstruct amdgpu_semaphore { 1343f012e29Smrg atomic_t refcount; 1353f012e29Smrg struct list_head list; 1363f012e29Smrg struct amdgpu_cs_fence signal_fence; 1373f012e29Smrg}; 1383f012e29Smrg 1393f012e29Smrg/** 1403f012e29Smrg * Functions. 1413f012e29Smrg */ 1423f012e29Smrg 1433f012e29Smrgdrm_private void amdgpu_vamgr_init(struct amdgpu_bo_va_mgr *mgr, uint64_t start, 1443f012e29Smrg uint64_t max, uint64_t alignment); 1453f012e29Smrg 1463f012e29Smrgdrm_private void amdgpu_vamgr_deinit(struct amdgpu_bo_va_mgr *mgr); 1473f012e29Smrg 14800a23bdaSmrgdrm_private void amdgpu_parse_asic_ids(struct amdgpu_device *dev); 149d8807b2fSmrg 1503f012e29Smrgdrm_private int amdgpu_query_gpu_info_init(amdgpu_device_handle dev); 1513f012e29Smrg 1523f012e29Smrgdrm_private uint64_t amdgpu_cs_calculate_timeout(uint64_t timeout); 1533f012e29Smrg 1543f012e29Smrg/** 1553f012e29Smrg * Inline functions. 1563f012e29Smrg */ 1573f012e29Smrg 1583f012e29Smrg/** 1593f012e29Smrg * Increment src and decrement dst as if we were updating references 1603f012e29Smrg * for an assignment between 2 pointers of some objects. 1613f012e29Smrg * 1623f012e29Smrg * \return true if dst is 0 1633f012e29Smrg */ 1643f012e29Smrgstatic inline bool update_references(atomic_t *dst, atomic_t *src) 1653f012e29Smrg{ 1663f012e29Smrg if (dst != src) { 1673f012e29Smrg /* bump src first */ 1683f012e29Smrg if (src) { 1693f012e29Smrg assert(atomic_read(src) > 0); 1703f012e29Smrg atomic_inc(src); 1713f012e29Smrg } 1723f012e29Smrg if (dst) { 1733f012e29Smrg assert(atomic_read(dst) > 0); 1743f012e29Smrg return atomic_dec_and_test(dst); 1753f012e29Smrg } 1763f012e29Smrg } 1773f012e29Smrg return false; 1783f012e29Smrg} 1793f012e29Smrg 1803f012e29Smrg#endif 181