Path: blob/21.2-virgl/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h
4561 views
/*1* Copyright © 2008 Jérôme Glisse2* Copyright © 2011 Marek Olšák <[email protected]>3* Copyright © 2015 Advanced Micro Devices, Inc.4* All Rights Reserved.5*6* Permission is hereby granted, free of charge, to any person obtaining7* a copy of this software and associated documentation files (the8* "Software"), to deal in the Software without restriction, including9* without limitation the rights to use, copy, modify, merge, publish,10* distribute, sub license, and/or sell copies of the Software, and to11* permit persons to whom the Software is furnished to do so, subject to12* the following conditions:13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES16* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS18* AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,20* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE21* USE OR OTHER DEALINGS IN THE SOFTWARE.22*23* The above copyright notice and this permission notice (including the24* next paragraph) shall be included in all copies or substantial portions25* of the Software.26*/2728#ifndef AMDGPU_BO_H29#define AMDGPU_BO_H3031#include "amdgpu_winsys.h"3233#include "pipebuffer/pb_slab.h"3435struct amdgpu_sparse_backing_chunk;3637/*38* Sub-allocation information for a real buffer used as backing memory of a39* sparse buffer.40*/41struct amdgpu_sparse_backing {42struct list_head list;4344struct amdgpu_winsys_bo *bo;4546/* Sorted list of free chunks. */47struct amdgpu_sparse_backing_chunk *chunks;48uint32_t max_chunks;49uint32_t num_chunks;50};5152struct amdgpu_sparse_commitment {53struct amdgpu_sparse_backing *backing;54uint32_t page;55};5657struct amdgpu_winsys_bo {58struct pb_buffer base;59union {60struct {61amdgpu_va_handle va_handle;62#if DEBUG63struct list_head global_list_item;64#endif65void *cpu_ptr; /* for user_ptr and permanent maps */66uint32_t kms_handle;67int map_count;6869bool is_user_ptr;70bool use_reusable_pool;7172/* Whether buffer_get_handle or buffer_from_handle has been called,73* it can only transition from false to true. Protected by lock.74*/75bool is_shared;76} real;77struct {78struct pb_slab_entry entry;79struct amdgpu_winsys_bo *real;80} slab;81struct {82amdgpu_va_handle va_handle;8384uint32_t num_va_pages;85uint32_t num_backing_pages;8687struct list_head backing;8889/* Commitment information for each page of the virtual memory area. */90struct amdgpu_sparse_commitment *commitments;91} sparse;92} u;9394amdgpu_bo_handle bo; /* NULL for slab entries and sparse buffers */95uint64_t va;9697uint32_t unique_id;98simple_mtx_t lock;99100/* how many command streams, which are being emitted in a separate101* thread, is this bo referenced in? */102volatile int num_active_ioctls;103104/* Fences for buffer synchronization. */105uint16_t num_fences;106uint16_t max_fences;107struct pipe_fence_handle **fences;108109struct pb_cache_entry cache_entry[];110};111112struct amdgpu_slab {113struct pb_slab base;114unsigned entry_size;115struct amdgpu_winsys_bo *buffer;116struct amdgpu_winsys_bo *entries;117};118119bool amdgpu_bo_can_reclaim(struct amdgpu_winsys *ws, struct pb_buffer *_buf);120struct pb_buffer *amdgpu_bo_create(struct amdgpu_winsys *ws,121uint64_t size,122unsigned alignment,123enum radeon_bo_domain domain,124enum radeon_bo_flag flags);125void amdgpu_bo_destroy(struct amdgpu_winsys *ws, struct pb_buffer *_buf);126void *amdgpu_bo_map(struct radeon_winsys *rws,127struct pb_buffer *buf,128struct radeon_cmdbuf *rcs,129enum pipe_map_flags usage);130void amdgpu_bo_unmap(struct radeon_winsys *rws, struct pb_buffer *buf);131void amdgpu_bo_init_functions(struct amdgpu_screen_winsys *ws);132133bool amdgpu_bo_can_reclaim_slab(void *priv, struct pb_slab_entry *entry);134struct pb_slab *amdgpu_bo_slab_alloc_encrypted(void *priv, unsigned heap,135unsigned entry_size,136unsigned group_index);137struct pb_slab *amdgpu_bo_slab_alloc_normal(void *priv, unsigned heap,138unsigned entry_size,139unsigned group_index);140void amdgpu_bo_slab_free(struct amdgpu_winsys *ws, struct pb_slab *slab);141142static inline143struct amdgpu_winsys_bo *amdgpu_winsys_bo(struct pb_buffer *bo)144{145return (struct amdgpu_winsys_bo *)bo;146}147148static inline149struct amdgpu_slab *amdgpu_slab(struct pb_slab *slab)150{151return (struct amdgpu_slab *)slab;152}153154static inline155void amdgpu_winsys_bo_reference(struct amdgpu_winsys *ws,156struct amdgpu_winsys_bo **dst,157struct amdgpu_winsys_bo *src)158{159radeon_bo_reference(&ws->dummy_ws.base,160(struct pb_buffer**)dst, (struct pb_buffer*)src);161}162163#endif164165166