Path: blob/21.2-virgl/src/gallium/drivers/vc4/kernel/vc4_gem.c
4574 views
/*1* Copyright © 2014 Broadcom2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#ifdef USE_VC4_SIMULATOR2425#include "vc4_drv.h"2627/*28* Copies in the user's binning command list and generates the validated bin29* CL, along with associated data (shader records, uniforms).30*/31static int32vc4_get_bcl(struct drm_device *dev, struct vc4_exec_info *exec)33{34struct drm_vc4_submit_cl *args = exec->args;35void *temp = NULL;36void *bin;37int ret = 0;38uint32_t bin_offset = 0;39uint32_t shader_rec_offset = roundup(bin_offset + args->bin_cl_size,4016);41uint32_t uniforms_offset = shader_rec_offset + args->shader_rec_size;42uint32_t exec_size = uniforms_offset + args->uniforms_size;43uint32_t temp_size = exec_size + (sizeof(struct vc4_shader_state) *44args->shader_rec_count);4546if (uniforms_offset < shader_rec_offset ||47exec_size < uniforms_offset ||48args->shader_rec_count >= (UINT_MAX /49sizeof(struct vc4_shader_state)) ||50temp_size < exec_size) {51DRM_ERROR("overflow in exec arguments\n");52goto fail;53}5455/* Allocate space where we'll store the copied in user command lists56* and shader records.57*58* We don't just copy directly into the BOs because we need to59* read the contents back for validation, and I think the60* bo->vaddr is uncached access.61*/62temp = kmalloc(temp_size, GFP_KERNEL);63if (!temp) {64DRM_ERROR("Failed to allocate storage for copying "65"in bin/render CLs.\n");66ret = -ENOMEM;67goto fail;68}69bin = temp + bin_offset;70exec->shader_rec_u = temp + shader_rec_offset;71exec->uniforms_u = temp + uniforms_offset;72exec->shader_state = temp + exec_size;73exec->shader_state_size = args->shader_rec_count;7475ret = copy_from_user(bin,76(void __user *)(uintptr_t)args->bin_cl,77args->bin_cl_size);78if (ret) {79DRM_ERROR("Failed to copy in bin cl\n");80goto fail;81}8283ret = copy_from_user(exec->shader_rec_u,84(void __user *)(uintptr_t)args->shader_rec,85args->shader_rec_size);86if (ret) {87DRM_ERROR("Failed to copy in shader recs\n");88goto fail;89}9091ret = copy_from_user(exec->uniforms_u,92(void __user *)(uintptr_t)args->uniforms,93args->uniforms_size);94if (ret) {95DRM_ERROR("Failed to copy in uniforms cl\n");96goto fail;97}9899exec->exec_bo = drm_gem_cma_create(dev, exec_size);100#if 0101if (IS_ERR(exec->exec_bo)) {102DRM_ERROR("Couldn't allocate BO for exec\n");103ret = PTR_ERR(exec->exec_bo);104exec->exec_bo = NULL;105goto fail;106}107#endif108109list_addtail(&to_vc4_bo(&exec->exec_bo->base)->unref_head,110&exec->unref_list);111112exec->ct0ca = exec->exec_bo->paddr + bin_offset;113114exec->bin_u = bin;115116exec->shader_rec_v = exec->exec_bo->vaddr + shader_rec_offset;117exec->shader_rec_p = exec->exec_bo->paddr + shader_rec_offset;118exec->shader_rec_size = args->shader_rec_size;119120exec->uniforms_v = exec->exec_bo->vaddr + uniforms_offset;121exec->uniforms_p = exec->exec_bo->paddr + uniforms_offset;122exec->uniforms_size = args->uniforms_size;123124ret = vc4_validate_bin_cl(dev,125exec->exec_bo->vaddr + bin_offset,126bin,127exec);128if (ret)129goto fail;130131ret = vc4_validate_shader_recs(dev, exec);132133fail:134kfree(temp);135return ret;136}137138int139vc4_cl_validate(struct drm_device *dev, struct vc4_exec_info *exec)140{141struct drm_vc4_submit_cl *args = exec->args;142int ret = 0;143144if (args->color_write.bits & VC4_RENDER_CONFIG_MS_MODE_4X) {145exec->tile_width = 32;146exec->tile_height = 32;147} else {148exec->tile_width = 64;149exec->tile_height = 64;150}151152if (exec->args->bin_cl_size != 0) {153ret = vc4_get_bcl(dev, exec);154if (ret)155goto fail;156} else {157exec->ct0ca = exec->ct0ea = 0;158}159160ret = vc4_get_rcl(dev, exec);161if (ret)162goto fail;163164fail:165return ret;166}167168#endif /* USE_VC4_SIMULATOR */169170171