14f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/* 2e2bf57f84109f32da5a5bdbfa430d2b81a7fff02Dan Handley * Copyright © 2014 Broadcom 34f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * 44f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Permission is hereby granted, free of charge, to any person obtaining a 54f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * copy of this software and associated documentation files (the "Software"), 64f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * to deal in the Software without restriction, including without limitation 74f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * the rights to use, copy, modify, merge, publish, distribute, sublicense, 84f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * and/or sell copies of the Software, and to permit persons to whom the 94f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Software is furnished to do so, subject to the following conditions: 104f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * 114f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * The above copyright notice and this permission notice (including the next 124f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * paragraph) shall be included in all copies or substantial portions of the 134f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Software. 144f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * 154f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 164f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 174f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 184f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 194f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 204f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 214f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * IN THE SOFTWARE. 224f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta */ 234f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 244f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta#ifndef VC4_DRV_H 254f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta#define VC4_DRV_H 264f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 274f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta#include "vc4_simulator_validate.h" 284f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 294f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Guptastruct vc4_exec_info { 30e2bf57f84109f32da5a5bdbfa430d2b81a7fff02Dan Handley /* Sequence number for this bin/render job. */ 31e2bf57f84109f32da5a5bdbfa430d2b81a7fff02Dan Handley uint64_t seqno; 324f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 3397043ac98e13a726dbf8b3b41654dca759e3da2cDan Handley /* Kernel-space copy of the ioctl arguments */ 3497043ac98e13a726dbf8b3b41654dca759e3da2cDan Handley struct drm_vc4_submit_cl *args; 3597043ac98e13a726dbf8b3b41654dca759e3da2cDan Handley 364f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta /* This is the array of BOs that were looked up at the start of exec. 374f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Command validation will use indices into this array. 384f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta */ 394f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta struct drm_gem_cma_object **bo; 404f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta uint32_t bo_count; 414f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 424f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta /* List of other BOs used in the job that need to be released 434f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * once the job is complete. 444f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta */ 454f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta struct list_head unref_list; 464f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 4707f4e078b6871e5c74f6cb38f2726a2cfcb2b746Achin Gupta /* Current unvalidated indices into @bo loaded by the non-hardware 484f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * VC4_PACKET_GEM_HANDLES. 4907f4e078b6871e5c74f6cb38f2726a2cfcb2b746Achin Gupta */ 5007f4e078b6871e5c74f6cb38f2726a2cfcb2b746Achin Gupta uint32_t bo_index[2]; 514f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 524f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta /* This is the BO where we store the validated command lists, shader 534f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * records, and uniforms. 544f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta */ 5507f4e078b6871e5c74f6cb38f2726a2cfcb2b746Achin Gupta struct drm_gem_cma_object *exec_bo; 5607f4e078b6871e5c74f6cb38f2726a2cfcb2b746Achin Gupta 5707f4e078b6871e5c74f6cb38f2726a2cfcb2b746Achin Gupta /** 5807f4e078b6871e5c74f6cb38f2726a2cfcb2b746Achin Gupta * This tracks the per-shader-record state (packet 64) that 594f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * determines the length of the shader record and the offset 604f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * it's expected to be found at. It gets read in from the 614f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * command lists. 624f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta */ 637935d0a59d439c993b79814ab414d37e4a90d9a6Andrew Thoelke struct vc4_shader_state { 644f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta uint32_t addr; 654f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta /* Maximum vertex index referenced by any primitive using this 664f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * shader state. 674f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta */ 684f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta uint32_t max_index; 69e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux } *shader_state; 70e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux 71e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux /** How many shader states the user declared they were using. */ 72e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux uint32_t shader_state_size; 73e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux /** How many shader state records the validator has seen. */ 74e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux uint32_t shader_state_count; 75e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux 76e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux bool found_tile_binning_mode_config_packet; 77e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux bool found_start_tile_binning_packet; 78e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux bool found_increment_semaphore_packet; 79e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux bool found_flush; 80e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux uint8_t bin_tiles_x, bin_tiles_y; 81e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux struct drm_gem_cma_object *tile_bo; 82e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux uint32_t tile_alloc_offset; 83e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux 84e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux uint32_t tile_width, tile_height; 85e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux 86e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux /** 87e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux * Computed addresses pointing into exec_bo where we start the 884f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * bin thread (ct0) and render thread (ct1). 89a7934d69508872919787742c7680b68807c24361Jeenu Viswambharan */ 90e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux uint32_t ct0ca, ct0ea; 91a7934d69508872919787742c7680b68807c24361Jeenu Viswambharan uint32_t ct1ca, ct1ea; 92e0ae9fab61263bf7ec5beaa8256c573f09c744f0Sandrine Bailleux 93a7934d69508872919787742c7680b68807c24361Jeenu Viswambharan /* Pointer to the unvalidated bin CL (if present). */ 94a7934d69508872919787742c7680b68807c24361Jeenu Viswambharan void *bin_u; 95a7934d69508872919787742c7680b68807c24361Jeenu Viswambharan 96a7934d69508872919787742c7680b68807c24361Jeenu Viswambharan /* Pointers to the shader recs. These paddr gets incremented as CL 97a7934d69508872919787742c7680b68807c24361Jeenu Viswambharan * packets are relocated in validate_gl_shader_state, and the vaddrs 98a7934d69508872919787742c7680b68807c24361Jeenu Viswambharan * (u and v) get incremented and size decremented as the shader recs 99a7934d69508872919787742c7680b68807c24361Jeenu Viswambharan * themselves are validated. 1000a30cf54af7bb1f77b405062b1d5b44e809d0290Andrew Thoelke */ 1010a30cf54af7bb1f77b405062b1d5b44e809d0290Andrew Thoelke void *shader_rec_u; 1020a30cf54af7bb1f77b405062b1d5b44e809d0290Andrew Thoelke void *shader_rec_v; 1030a30cf54af7bb1f77b405062b1d5b44e809d0290Andrew Thoelke uint32_t shader_rec_p; 1040a30cf54af7bb1f77b405062b1d5b44e809d0290Andrew Thoelke uint32_t shader_rec_size; 1050a30cf54af7bb1f77b405062b1d5b44e809d0290Andrew Thoelke 1060a30cf54af7bb1f77b405062b1d5b44e809d0290Andrew Thoelke /* Pointers to the uniform data. These pointers are incremented, and 1070a30cf54af7bb1f77b405062b1d5b44e809d0290Andrew Thoelke * size decremented, as each batch of uniforms is uploaded. 1080a30cf54af7bb1f77b405062b1d5b44e809d0290Andrew Thoelke */ 1098b779620d3bad024b83650ecfeaafd7b3ae26ccfKévin Petit void *uniforms_u; 1100a30cf54af7bb1f77b405062b1d5b44e809d0290Andrew Thoelke void *uniforms_v; 1110a30cf54af7bb1f77b405062b1d5b44e809d0290Andrew Thoelke uint32_t uniforms_p; 1122bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke uint32_t uniforms_size; 1138b779620d3bad024b83650ecfeaafd7b3ae26ccfKévin Petit}; 1148b779620d3bad024b83650ecfeaafd7b3ae26ccfKévin Petit 1158b779620d3bad024b83650ecfeaafd7b3ae26ccfKévin Petit/** 1168b779620d3bad024b83650ecfeaafd7b3ae26ccfKévin Petit * struct vc4_texture_sample_info - saves the offsets into the UBO for texture 1178b779620d3bad024b83650ecfeaafd7b3ae26ccfKévin Petit * setup parameters. 1188b779620d3bad024b83650ecfeaafd7b3ae26ccfKévin Petit * 1198b779620d3bad024b83650ecfeaafd7b3ae26ccfKévin Petit * This will be used at draw time to relocate the reference to the texture 1208b779620d3bad024b83650ecfeaafd7b3ae26ccfKévin Petit * contents in p0, and validate that the offset combined with 1212bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke * width/height/stride/etc. from p1 and p2/p3 doesn't sample outside the BO. 1225c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * Note that the hardware treats unprovided config parameters as 0, so not all 1237a24cba5c236a6f67f689baa5deed7f76903ea7aSoby Mathew * of them need to be set up for every texure sample, and we'll store ~0 as 1245c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * the offset to mark the unused ones. 1255c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * 1267a24cba5c236a6f67f689baa5deed7f76903ea7aSoby Mathew * See the VC4 3D architecture guide page 41 ("Texture and Memory Lookup Unit 1275c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * Setup") for definitions of the texture parameters. 1285c8babcd70149db57734a38be432fe6625f3888fSoby Mathew */ 1295c8babcd70149db57734a38be432fe6625f3888fSoby Mathewstruct vc4_texture_sample_info { 1305c8babcd70149db57734a38be432fe6625f3888fSoby Mathew bool is_direct; 1315c8babcd70149db57734a38be432fe6625f3888fSoby Mathew uint32_t p_offset[4]; 1325c8babcd70149db57734a38be432fe6625f3888fSoby Mathew}; 1335c8babcd70149db57734a38be432fe6625f3888fSoby Mathew 1345c8babcd70149db57734a38be432fe6625f3888fSoby Mathew/** 1355c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * struct vc4_validated_shader_info - information about validated shaders that 1365c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * needs to be used from command list validation. 1375c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * 1385c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * For a given shader, each time a shader state record references it, we need 1395c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * to verify that the shader doesn't read more uniforms than the shader state 1405c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * record's uniform BO pointer can provide, and we need to apply relocations 1415c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * and validate the shader state record's uniforms that define the texture 1425c8babcd70149db57734a38be432fe6625f3888fSoby Mathew * samples. 1435c8babcd70149db57734a38be432fe6625f3888fSoby Mathew */ 1445c8babcd70149db57734a38be432fe6625f3888fSoby Mathewstruct vc4_validated_shader_info 1452bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke{ 1462bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke uint32_t uniforms_size; 1472bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke uint32_t uniforms_src_size; 1482bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke uint32_t num_texture_samples; 1492bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke struct vc4_texture_sample_info *texture_samples; 1502bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke 1512bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke uint32_t num_uniform_addr_offsets; 1522bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke uint32_t *uniform_addr_offsets; 1532bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke 1542bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke bool is_threaded; 1552bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke}; 1562bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke 1572bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke/* vc4_validate.c */ 1582bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelkeint 1592bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelkevc4_validate_bin_cl(struct drm_device *dev, 160674878464a93bb6d6bf6cb746fc4b9dba6e101acSoby Mathew void *validated, 1612bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke void *unvalidated, 1622bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke struct vc4_exec_info *exec); 1632bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke 1642bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelkeint 1652bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelkevc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec); 1662bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke 1672bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelkestruct vc4_validated_shader_info * 1682bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelkevc4_validate_shader(struct drm_gem_cma_object *shader_obj); 1692bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke 1702bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelkestruct drm_gem_cma_object *vc4_use_bo(struct vc4_exec_info *exec, 1712bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke uint32_t hindex); 1722bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke 1732bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelkeint vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec); 1742bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke 175674878464a93bb6d6bf6cb746fc4b9dba6e101acSoby Mathewbool vc4_check_tex_size(struct vc4_exec_info *exec, 1762bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke struct drm_gem_cma_object *fbo, 1772bf28e620a6f05700753a2b45a888c6623e20723Andrew Thoelke uint32_t offset, uint8_t tiling_format, 17812d0d00d1e4714fc59c4abbe1d8a2a3ae8a84f56Soby Mathew uint32_t width, uint32_t height, uint8_t cpp); 17912d0d00d1e4714fc59c4abbe1d8a2a3ae8a84f56Soby Mathew 18012d0d00d1e4714fc59c4abbe1d8a2a3ae8a84f56Soby Mathew#endif /* VC4_DRV_H */ 18112d0d00d1e4714fc59c4abbe1d8a2a3ae8a84f56Soby Mathew