1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2014-2017 Broadcom 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include "util/u_math.h" 25bf215546Sopenharmony_ci#include "util/ralloc.h" 26bf215546Sopenharmony_ci#include "v3d_context.h" 27bf215546Sopenharmony_ci/* We don't expect that the packets we use in this file change across across 28bf215546Sopenharmony_ci * hw versions, so we just explicitly set the V3D_VERSION and include 29bf215546Sopenharmony_ci * v3dx_pack here 30bf215546Sopenharmony_ci */ 31bf215546Sopenharmony_ci#define V3D_VERSION 33 32bf215546Sopenharmony_ci#include "broadcom/common/v3d_macros.h" 33bf215546Sopenharmony_ci#include "broadcom/cle/v3dx_pack.h" 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_civoid 36bf215546Sopenharmony_civ3d_init_cl(struct v3d_job *job, struct v3d_cl *cl) 37bf215546Sopenharmony_ci{ 38bf215546Sopenharmony_ci cl->base = NULL; 39bf215546Sopenharmony_ci cl->next = cl->base; 40bf215546Sopenharmony_ci cl->size = 0; 41bf215546Sopenharmony_ci cl->job = job; 42bf215546Sopenharmony_ci} 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ciuint32_t 45bf215546Sopenharmony_civ3d_cl_ensure_space(struct v3d_cl *cl, uint32_t space, uint32_t alignment) 46bf215546Sopenharmony_ci{ 47bf215546Sopenharmony_ci uint32_t offset = align(cl_offset(cl), alignment); 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci if (offset + space <= cl->size) { 50bf215546Sopenharmony_ci cl->next = cl->base + offset; 51bf215546Sopenharmony_ci return offset; 52bf215546Sopenharmony_ci } 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci v3d_bo_unreference(&cl->bo); 55bf215546Sopenharmony_ci cl->bo = v3d_bo_alloc(cl->job->v3d->screen, align(space, 4096), "CL"); 56bf215546Sopenharmony_ci cl->base = v3d_bo_map(cl->bo); 57bf215546Sopenharmony_ci cl->size = cl->bo->size; 58bf215546Sopenharmony_ci cl->next = cl->base; 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci return 0; 61bf215546Sopenharmony_ci} 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_civoid 64bf215546Sopenharmony_civ3d_cl_ensure_space_with_branch(struct v3d_cl *cl, uint32_t space) 65bf215546Sopenharmony_ci{ 66bf215546Sopenharmony_ci if (cl_offset(cl) + space + cl_packet_length(BRANCH) <= cl->size) 67bf215546Sopenharmony_ci return; 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci struct v3d_bo *new_bo = v3d_bo_alloc(cl->job->v3d->screen, space, "CL"); 70bf215546Sopenharmony_ci assert(space <= new_bo->size); 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci /* Chain to the new BO from the old one. */ 73bf215546Sopenharmony_ci if (cl->bo) { 74bf215546Sopenharmony_ci cl_emit(cl, BRANCH, branch) { 75bf215546Sopenharmony_ci branch.address = cl_address(new_bo, 0); 76bf215546Sopenharmony_ci } 77bf215546Sopenharmony_ci v3d_bo_unreference(&cl->bo); 78bf215546Sopenharmony_ci } else { 79bf215546Sopenharmony_ci /* Root the first RCL/BCL BO in the job. */ 80bf215546Sopenharmony_ci v3d_job_add_bo(cl->job, new_bo); 81bf215546Sopenharmony_ci } 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci cl->bo = new_bo; 84bf215546Sopenharmony_ci cl->base = v3d_bo_map(cl->bo); 85bf215546Sopenharmony_ci cl->size = cl->bo->size; 86bf215546Sopenharmony_ci cl->next = cl->base; 87bf215546Sopenharmony_ci} 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_civoid 90bf215546Sopenharmony_civ3d_destroy_cl(struct v3d_cl *cl) 91bf215546Sopenharmony_ci{ 92bf215546Sopenharmony_ci v3d_bo_unreference(&cl->bo); 93bf215546Sopenharmony_ci} 94