101e04c3fSmrg/* 201e04c3fSmrg * Copyright © 2016 Red Hat. 301e04c3fSmrg * Copyright © 2016 Bas Nieuwenhuizen 401e04c3fSmrg * 501e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 601e04c3fSmrg * copy of this software and associated documentation files (the "Software"), 701e04c3fSmrg * to deal in the Software without restriction, including without limitation 801e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 901e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the 1001e04c3fSmrg * Software is furnished to do so, subject to the following conditions: 1101e04c3fSmrg * 1201e04c3fSmrg * The above copyright notice and this permission notice (including the next 1301e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the 1401e04c3fSmrg * Software. 1501e04c3fSmrg * 1601e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1701e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1801e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1901e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2001e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2101e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 2201e04c3fSmrg * IN THE SOFTWARE. 2301e04c3fSmrg */ 2401e04c3fSmrg 2501e04c3fSmrg#ifndef RADV_CS_H 2601e04c3fSmrg#define RADV_CS_H 2701e04c3fSmrg 2801e04c3fSmrg#include <assert.h> 297ec681f3Smrg#include <stdint.h> 307ec681f3Smrg#include <string.h> 317ec681f3Smrg#include "radv_private.h" 3201e04c3fSmrg#include "sid.h" 3301e04c3fSmrg 347ec681f3Smrgstatic inline unsigned 357ec681f3Smrgradeon_check_space(struct radeon_winsys *ws, struct radeon_cmdbuf *cs, unsigned needed) 367ec681f3Smrg{ 377ec681f3Smrg if (cs->max_dw - cs->cdw < needed) 387ec681f3Smrg ws->cs_grow(cs, needed); 397ec681f3Smrg return cs->cdw + needed; 407ec681f3Smrg} 417ec681f3Smrg 427ec681f3Smrgstatic inline void 437ec681f3Smrgradeon_set_config_reg_seq(struct radeon_cmdbuf *cs, unsigned reg, unsigned num) 447ec681f3Smrg{ 457ec681f3Smrg assert(reg >= SI_CONFIG_REG_OFFSET && reg < SI_CONFIG_REG_END); 467ec681f3Smrg assert(cs->cdw + 2 + num <= cs->max_dw); 477ec681f3Smrg assert(num); 487ec681f3Smrg radeon_emit(cs, PKT3(PKT3_SET_CONFIG_REG, num, 0)); 497ec681f3Smrg radeon_emit(cs, (reg - SI_CONFIG_REG_OFFSET) >> 2); 507ec681f3Smrg} 517ec681f3Smrg 527ec681f3Smrgstatic inline void 537ec681f3Smrgradeon_set_config_reg(struct radeon_cmdbuf *cs, unsigned reg, unsigned value) 5401e04c3fSmrg{ 557ec681f3Smrg radeon_set_config_reg_seq(cs, reg, 1); 567ec681f3Smrg radeon_emit(cs, value); 5701e04c3fSmrg} 5801e04c3fSmrg 597ec681f3Smrgstatic inline void 607ec681f3Smrgradeon_set_context_reg_seq(struct radeon_cmdbuf *cs, unsigned reg, unsigned num) 6101e04c3fSmrg{ 627ec681f3Smrg assert(reg >= SI_CONTEXT_REG_OFFSET && reg < SI_CONTEXT_REG_END); 637ec681f3Smrg assert(cs->cdw + 2 + num <= cs->max_dw); 647ec681f3Smrg assert(num); 657ec681f3Smrg radeon_emit(cs, PKT3(PKT3_SET_CONTEXT_REG, num, 0)); 667ec681f3Smrg radeon_emit(cs, (reg - SI_CONTEXT_REG_OFFSET) >> 2); 6701e04c3fSmrg} 6801e04c3fSmrg 697ec681f3Smrgstatic inline void 707ec681f3Smrgradeon_set_context_reg(struct radeon_cmdbuf *cs, unsigned reg, unsigned value) 7101e04c3fSmrg{ 727ec681f3Smrg radeon_set_context_reg_seq(cs, reg, 1); 737ec681f3Smrg radeon_emit(cs, value); 7401e04c3fSmrg} 7501e04c3fSmrg 767ec681f3Smrgstatic inline void 777ec681f3Smrgradeon_set_context_reg_idx(struct radeon_cmdbuf *cs, unsigned reg, unsigned idx, unsigned value) 7801e04c3fSmrg{ 797ec681f3Smrg assert(reg >= SI_CONTEXT_REG_OFFSET && reg < SI_CONTEXT_REG_END); 807ec681f3Smrg assert(cs->cdw + 3 <= cs->max_dw); 817ec681f3Smrg radeon_emit(cs, PKT3(PKT3_SET_CONTEXT_REG, 1, 0)); 827ec681f3Smrg radeon_emit(cs, (reg - SI_CONTEXT_REG_OFFSET) >> 2 | (idx << 28)); 837ec681f3Smrg radeon_emit(cs, value); 8401e04c3fSmrg} 8501e04c3fSmrg 867ec681f3Smrgstatic inline void 877ec681f3Smrgradeon_set_context_reg_rmw(struct radeon_cmdbuf *cs, unsigned reg, unsigned value, unsigned mask) 8801e04c3fSmrg{ 897ec681f3Smrg assert(reg >= SI_CONTEXT_REG_OFFSET && reg < SI_CONTEXT_REG_END); 907ec681f3Smrg assert(cs->cdw + 4 <= cs->max_dw); 917ec681f3Smrg radeon_emit(cs, PKT3(PKT3_CONTEXT_REG_RMW, 2, 0)); 927ec681f3Smrg radeon_emit(cs, (reg - SI_CONTEXT_REG_OFFSET) >> 2); 937ec681f3Smrg radeon_emit(cs, mask); 947ec681f3Smrg radeon_emit(cs, value); 9501e04c3fSmrg} 9601e04c3fSmrg 977ec681f3Smrgstatic inline void 987ec681f3Smrgradeon_set_sh_reg_seq(struct radeon_cmdbuf *cs, unsigned reg, unsigned num) 997ec681f3Smrg{ 1007ec681f3Smrg assert(reg >= SI_SH_REG_OFFSET && reg < SI_SH_REG_END); 1017ec681f3Smrg assert(cs->cdw + 2 + num <= cs->max_dw); 1027ec681f3Smrg assert(num); 1037ec681f3Smrg radeon_emit(cs, PKT3(PKT3_SET_SH_REG, num, 0)); 1047ec681f3Smrg radeon_emit(cs, (reg - SI_SH_REG_OFFSET) >> 2); 1057ec681f3Smrg} 1067ec681f3Smrg 1077ec681f3Smrgstatic inline void 1087ec681f3Smrgradeon_set_sh_reg(struct radeon_cmdbuf *cs, unsigned reg, unsigned value) 1097ec681f3Smrg{ 1107ec681f3Smrg radeon_set_sh_reg_seq(cs, reg, 1); 1117ec681f3Smrg radeon_emit(cs, value); 1127ec681f3Smrg} 11301e04c3fSmrg 1147ec681f3Smrgstatic inline void 1157ec681f3Smrgradeon_set_sh_reg_idx(const struct radv_physical_device *pdevice, struct radeon_cmdbuf *cs, 1167ec681f3Smrg unsigned reg, unsigned idx, unsigned value) 11701e04c3fSmrg{ 1187ec681f3Smrg assert(reg >= SI_SH_REG_OFFSET && reg < SI_SH_REG_END); 1197ec681f3Smrg assert(cs->cdw + 3 <= cs->max_dw); 1207ec681f3Smrg assert(idx); 1217ec681f3Smrg 1227ec681f3Smrg unsigned opcode = PKT3_SET_SH_REG_INDEX; 1237ec681f3Smrg if (pdevice->rad_info.chip_class < GFX10) 1247ec681f3Smrg opcode = PKT3_SET_SH_REG; 1257ec681f3Smrg 1267ec681f3Smrg radeon_emit(cs, PKT3(opcode, 1, 0)); 1277ec681f3Smrg radeon_emit(cs, (reg - SI_SH_REG_OFFSET) >> 2 | (idx << 28)); 1287ec681f3Smrg radeon_emit(cs, value); 12901e04c3fSmrg} 13001e04c3fSmrg 1317ec681f3Smrgstatic inline void 1327ec681f3Smrgradeon_set_uconfig_reg_seq(struct radeon_cmdbuf *cs, unsigned reg, unsigned num) 13301e04c3fSmrg{ 1347ec681f3Smrg assert(reg >= CIK_UCONFIG_REG_OFFSET && reg < CIK_UCONFIG_REG_END); 1357ec681f3Smrg assert(cs->cdw + 2 + num <= cs->max_dw); 1367ec681f3Smrg assert(num); 1377ec681f3Smrg radeon_emit(cs, PKT3(PKT3_SET_UCONFIG_REG, num, 0)); 1387ec681f3Smrg radeon_emit(cs, (reg - CIK_UCONFIG_REG_OFFSET) >> 2); 13901e04c3fSmrg} 14001e04c3fSmrg 1417ec681f3Smrgstatic inline void 1427ec681f3Smrgradeon_set_uconfig_reg_seq_perfctr(struct radeon_cmdbuf *cs, unsigned reg, unsigned num) 14301e04c3fSmrg{ 1447ec681f3Smrg assert(reg >= CIK_UCONFIG_REG_OFFSET && reg < CIK_UCONFIG_REG_END); 1457ec681f3Smrg assert(cs->cdw + 2 + num <= cs->max_dw); 1467ec681f3Smrg assert(num); 1477ec681f3Smrg radeon_emit(cs, PKT3(PKT3_SET_UCONFIG_REG, num, 1)); 1487ec681f3Smrg radeon_emit(cs, (reg - CIK_UCONFIG_REG_OFFSET) >> 2); 14901e04c3fSmrg} 15001e04c3fSmrg 1517ec681f3Smrgstatic inline void 1527ec681f3Smrgradeon_set_uconfig_reg(struct radeon_cmdbuf *cs, unsigned reg, unsigned value) 15301e04c3fSmrg{ 1547ec681f3Smrg radeon_set_uconfig_reg_seq(cs, reg, 1); 1557ec681f3Smrg radeon_emit(cs, value); 15601e04c3fSmrg} 15701e04c3fSmrg 1587ec681f3Smrgstatic inline void 1597ec681f3Smrgradeon_set_uconfig_reg_idx(const struct radv_physical_device *pdevice, struct radeon_cmdbuf *cs, 1607ec681f3Smrg unsigned reg, unsigned idx, unsigned value) 16101e04c3fSmrg{ 1627ec681f3Smrg assert(reg >= CIK_UCONFIG_REG_OFFSET && reg < CIK_UCONFIG_REG_END); 1637ec681f3Smrg assert(cs->cdw + 3 <= cs->max_dw); 1647ec681f3Smrg assert(idx); 1657ec681f3Smrg 1667ec681f3Smrg unsigned opcode = PKT3_SET_UCONFIG_REG_INDEX; 1677ec681f3Smrg if (pdevice->rad_info.chip_class < GFX9 || 1687ec681f3Smrg (pdevice->rad_info.chip_class == GFX9 && pdevice->rad_info.me_fw_version < 26)) 1697ec681f3Smrg opcode = PKT3_SET_UCONFIG_REG; 1707ec681f3Smrg 1717ec681f3Smrg radeon_emit(cs, PKT3(opcode, 1, 0)); 1727ec681f3Smrg radeon_emit(cs, (reg - CIK_UCONFIG_REG_OFFSET) >> 2 | (idx << 28)); 1737ec681f3Smrg radeon_emit(cs, value); 17401e04c3fSmrg} 17501e04c3fSmrg 1767ec681f3Smrgstatic inline void 1777ec681f3Smrgradeon_set_privileged_config_reg(struct radeon_cmdbuf *cs, unsigned reg, unsigned value) 17801e04c3fSmrg{ 1797ec681f3Smrg assert(reg < CIK_UCONFIG_REG_OFFSET); 1807ec681f3Smrg assert(cs->cdw + 6 <= cs->max_dw); 1817ec681f3Smrg 1827ec681f3Smrg radeon_emit(cs, PKT3(PKT3_COPY_DATA, 4, 0)); 1837ec681f3Smrg radeon_emit(cs, COPY_DATA_SRC_SEL(COPY_DATA_IMM) | COPY_DATA_DST_SEL(COPY_DATA_PERF)); 1847ec681f3Smrg radeon_emit(cs, value); 1857ec681f3Smrg radeon_emit(cs, 0); /* unused */ 1867ec681f3Smrg radeon_emit(cs, reg >> 2); 1877ec681f3Smrg radeon_emit(cs, 0); /* unused */ 18801e04c3fSmrg} 18901e04c3fSmrg 19001e04c3fSmrg#endif /* RADV_CS_H */ 191