Path: blob/21.2-virgl/src/gallium/winsys/svga/drm/vmw_screen_pools.c
4573 views
/**********************************************************1* Copyright 2009-2015 VMware, Inc. All rights reserved.2*3* Permission is hereby granted, free of charge, to any person4* obtaining a copy of this software and associated documentation5* files (the "Software"), to deal in the Software without6* restriction, including without limitation the rights to use, copy,7* modify, merge, publish, distribute, sublicense, and/or sell copies8* of the Software, and to permit persons to whom the Software is9* furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23**********************************************************/242526#include "vmw_screen.h"2728#include "vmw_buffer.h"29#include "vmw_fence.h"3031#include "pipebuffer/pb_buffer.h"32#include "pipebuffer/pb_bufmgr.h"3334/**35* vmw_pools_cleanup - Destroy the buffer pools.36*37* @vws: pointer to a struct vmw_winsys_screen.38*/39void40vmw_pools_cleanup(struct vmw_winsys_screen *vws)41{42if (vws->pools.mob_shader_slab_fenced)43vws->pools.mob_shader_slab_fenced->destroy44(vws->pools.mob_shader_slab_fenced);45if (vws->pools.mob_shader_slab)46vws->pools.mob_shader_slab->destroy(vws->pools.mob_shader_slab);47if (vws->pools.mob_fenced)48vws->pools.mob_fenced->destroy(vws->pools.mob_fenced);49if (vws->pools.mob_cache)50vws->pools.mob_cache->destroy(vws->pools.mob_cache);5152if (vws->pools.query_fenced)53vws->pools.query_fenced->destroy(vws->pools.query_fenced);54if (vws->pools.query_mm)55vws->pools.query_mm->destroy(vws->pools.query_mm);5657if(vws->pools.gmr_fenced)58vws->pools.gmr_fenced->destroy(vws->pools.gmr_fenced);59if (vws->pools.gmr_mm)60vws->pools.gmr_mm->destroy(vws->pools.gmr_mm);61if (vws->pools.gmr_slab_fenced)62vws->pools.gmr_slab_fenced->destroy(vws->pools.gmr_slab_fenced);63if (vws->pools.gmr_slab)64vws->pools.gmr_slab->destroy(vws->pools.gmr_slab);6566if(vws->pools.gmr)67vws->pools.gmr->destroy(vws->pools.gmr);68}697071/**72* vmw_query_pools_init - Create a pool of query buffers.73*74* @vws: Pointer to a struct vmw_winsys_screen.75*76* Typically this pool should be created on demand when we77* detect that the app will be using queries. There's nothing78* special with this pool other than the backing kernel buffer sizes,79* which are limited to 8192.80* If there is a performance issue with allocation and freeing of the81* query slabs, it should be easily fixable by allocating them out82* of a buffer cache.83*/84boolean85vmw_query_pools_init(struct vmw_winsys_screen *vws)86{87struct pb_desc desc;8889desc.alignment = 16;90desc.usage = ~(VMW_BUFFER_USAGE_SHARED | VMW_BUFFER_USAGE_SYNC);9192vws->pools.query_mm = pb_slab_range_manager_create(vws->pools.gmr, 16, 128,93VMW_QUERY_POOL_SIZE,94&desc);95if (!vws->pools.query_mm)96return FALSE;9798vws->pools.query_fenced = simple_fenced_bufmgr_create(99vws->pools.query_mm, vws->fence_ops);100101if(!vws->pools.query_fenced)102goto out_no_query_fenced;103104return TRUE;105106out_no_query_fenced:107vws->pools.query_mm->destroy(vws->pools.query_mm);108return FALSE;109}110111/**112* vmw_mob_pool_init - Create a pool of fenced kernel buffers.113*114* @vws: Pointer to a struct vmw_winsys_screen.115*116* Typically this pool should be created on demand when we117* detect that the app will be using MOB buffers.118*/119boolean120vmw_mob_pools_init(struct vmw_winsys_screen *vws)121{122struct pb_desc desc;123124vws->pools.mob_cache =125pb_cache_manager_create(vws->pools.gmr, 100000, 2.0f,126VMW_BUFFER_USAGE_SHARED,12764 * 1024 * 1024);128if (!vws->pools.mob_cache)129return FALSE;130131vws->pools.mob_fenced =132simple_fenced_bufmgr_create(vws->pools.mob_cache,133vws->fence_ops);134if(!vws->pools.mob_fenced)135goto out_no_mob_fenced;136137desc.alignment = 64;138desc.usage = ~(SVGA_BUFFER_USAGE_PINNED | VMW_BUFFER_USAGE_SHARED |139VMW_BUFFER_USAGE_SYNC);140vws->pools.mob_shader_slab =141pb_slab_range_manager_create(vws->pools.mob_cache,14264,1438192,14416384,145&desc);146if(!vws->pools.mob_shader_slab)147goto out_no_mob_shader_slab;148149vws->pools.mob_shader_slab_fenced =150simple_fenced_bufmgr_create(vws->pools.mob_shader_slab,151vws->fence_ops);152if(!vws->pools.mob_shader_slab_fenced)153goto out_no_mob_shader_slab_fenced;154155return TRUE;156157out_no_mob_shader_slab_fenced:158vws->pools.mob_shader_slab->destroy(vws->pools.mob_shader_slab);159out_no_mob_shader_slab:160vws->pools.mob_fenced->destroy(vws->pools.mob_fenced);161out_no_mob_fenced:162vws->pools.mob_cache->destroy(vws->pools.mob_cache);163return FALSE;164}165166/**167* vmw_pools_init - Create a pool of GMR buffers.168*169* @vws: Pointer to a struct vmw_winsys_screen.170*/171boolean172vmw_pools_init(struct vmw_winsys_screen *vws)173{174struct pb_desc desc;175176vws->pools.gmr = vmw_gmr_bufmgr_create(vws);177if(!vws->pools.gmr)178goto error;179180if ((vws->base.have_gb_objects && vws->base.have_gb_dma) ||181!vws->base.have_gb_objects) {182/*183* A managed pool for DMA buffers.184*/185vws->pools.gmr_mm = mm_bufmgr_create(vws->pools.gmr,186VMW_GMR_POOL_SIZE,18712 /* 4096 alignment */);188if(!vws->pools.gmr_mm)189goto error;190191vws->pools.gmr_fenced = simple_fenced_bufmgr_create192(vws->pools.gmr_mm, vws->fence_ops);193194#ifdef DEBUG195vws->pools.gmr_fenced = pb_debug_manager_create(vws->pools.gmr_fenced,1964096,1974096);198#endif199if(!vws->pools.gmr_fenced)200goto error;201202/*203* The slab pool allocates buffers directly from the kernel except204* for very small buffers which are allocated from a slab in order205* not to waste memory, since a kernel buffer is a minimum 4096 bytes.206*207* Here we use it only for emergency in the case our pre-allocated208* managed buffer pool runs out of memory.209*/210211desc.alignment = 64;212desc.usage = ~(SVGA_BUFFER_USAGE_PINNED | SVGA_BUFFER_USAGE_SHADER |213VMW_BUFFER_USAGE_SHARED | VMW_BUFFER_USAGE_SYNC);214vws->pools.gmr_slab = pb_slab_range_manager_create(vws->pools.gmr,21564,2168192,21716384,218&desc);219if (!vws->pools.gmr_slab)220goto error;221222vws->pools.gmr_slab_fenced =223simple_fenced_bufmgr_create(vws->pools.gmr_slab, vws->fence_ops);224225if (!vws->pools.gmr_slab_fenced)226goto error;227}228229vws->pools.query_fenced = NULL;230vws->pools.query_mm = NULL;231vws->pools.mob_cache = NULL;232233if (vws->base.have_gb_objects && !vmw_mob_pools_init(vws))234goto error;235236return TRUE;237238error:239vmw_pools_cleanup(vws);240return FALSE;241}242243244