Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a6xx/fd6_pack.h
4574 views
/*1* Copyright © 2019 Google, Inc.2*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, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*/2223#ifndef FD6_PACK_H24#define FD6_PACK_H2526#include "a6xx.xml.h"2728struct fd_reg_pair {29uint32_t reg;30uint64_t value;31struct fd_bo *bo;32bool is_address;33bool bo_write;34uint32_t bo_offset;35uint32_t bo_shift;36};3738#define __bo_type struct fd_bo *3940#include "a6xx-pack.xml.h"41#include "adreno-pm4-pack.xml.h"4243#define __assert_eq(a, b) \44do { \45if ((a) != (b)) { \46fprintf(stderr, "assert failed: " #a " (0x%x) != " #b " (0x%x)\n", a, \47b); \48assert((a) == (b)); \49} \50} while (0)5152#define __ONE_REG(i, ...) \53do { \54const struct fd_reg_pair regs[] = {__VA_ARGS__}; \55/* NOTE: allow regs[0].reg==0, this happens in OUT_PKT() */ \56if (i < ARRAY_SIZE(regs) && (i == 0 || regs[i].reg > 0)) { \57__assert_eq(regs[0].reg + i, regs[i].reg); \58if (regs[i].bo) { \59ring->cur = p; \60p += 2; \61OUT_RELOC(ring, regs[i].bo, regs[i].bo_offset, regs[i].value, \62regs[i].bo_shift); \63} else { \64*p++ = regs[i].value; \65if (regs[i].is_address) \66*p++ = regs[i].value >> 32; \67} \68} \69} while (0)7071#define OUT_REG(ring, ...) \72do { \73const struct fd_reg_pair regs[] = {__VA_ARGS__}; \74unsigned count = ARRAY_SIZE(regs); \75\76STATIC_ASSERT(count > 0); \77STATIC_ASSERT(count <= 16); \78\79BEGIN_RING(ring, count + 1); \80uint32_t *p = ring->cur; \81*p++ = pm4_pkt4_hdr(regs[0].reg, count); \82\83__ONE_REG(0, __VA_ARGS__); \84__ONE_REG(1, __VA_ARGS__); \85__ONE_REG(2, __VA_ARGS__); \86__ONE_REG(3, __VA_ARGS__); \87__ONE_REG(4, __VA_ARGS__); \88__ONE_REG(5, __VA_ARGS__); \89__ONE_REG(6, __VA_ARGS__); \90__ONE_REG(7, __VA_ARGS__); \91__ONE_REG(8, __VA_ARGS__); \92__ONE_REG(9, __VA_ARGS__); \93__ONE_REG(10, __VA_ARGS__); \94__ONE_REG(11, __VA_ARGS__); \95__ONE_REG(12, __VA_ARGS__); \96__ONE_REG(13, __VA_ARGS__); \97__ONE_REG(14, __VA_ARGS__); \98__ONE_REG(15, __VA_ARGS__); \99ring->cur = p; \100} while (0)101102#define OUT_PKT(ring, opcode, ...) \103do { \104const struct fd_reg_pair regs[] = {__VA_ARGS__}; \105unsigned count = ARRAY_SIZE(regs); \106\107STATIC_ASSERT(count <= 16); \108\109BEGIN_RING(ring, count + 1); \110uint32_t *p = ring->cur; \111*p++ = pm4_pkt7_hdr(opcode, count); \112\113__ONE_REG(0, __VA_ARGS__); \114__ONE_REG(1, __VA_ARGS__); \115__ONE_REG(2, __VA_ARGS__); \116__ONE_REG(3, __VA_ARGS__); \117__ONE_REG(4, __VA_ARGS__); \118__ONE_REG(5, __VA_ARGS__); \119__ONE_REG(6, __VA_ARGS__); \120__ONE_REG(7, __VA_ARGS__); \121__ONE_REG(8, __VA_ARGS__); \122__ONE_REG(9, __VA_ARGS__); \123__ONE_REG(10, __VA_ARGS__); \124__ONE_REG(11, __VA_ARGS__); \125__ONE_REG(12, __VA_ARGS__); \126__ONE_REG(13, __VA_ARGS__); \127__ONE_REG(14, __VA_ARGS__); \128__ONE_REG(15, __VA_ARGS__); \129ring->cur = p; \130} while (0)131132/* similar to OUT_PKT() but appends specified # of dwords133* copied for buf to the end of the packet (ie. for use-134* cases like CP_LOAD_STATE)135*/136#define OUT_PKTBUF(ring, opcode, dwords, sizedwords, ...) \137do { \138const struct fd_reg_pair regs[] = {__VA_ARGS__}; \139unsigned count = ARRAY_SIZE(regs); \140\141STATIC_ASSERT(count <= 16); \142count += sizedwords; \143\144BEGIN_RING(ring, count + 1); \145uint32_t *p = ring->cur; \146*p++ = pm4_pkt7_hdr(opcode, count); \147\148__ONE_REG(0, __VA_ARGS__); \149__ONE_REG(1, __VA_ARGS__); \150__ONE_REG(2, __VA_ARGS__); \151__ONE_REG(3, __VA_ARGS__); \152__ONE_REG(4, __VA_ARGS__); \153__ONE_REG(5, __VA_ARGS__); \154__ONE_REG(6, __VA_ARGS__); \155__ONE_REG(7, __VA_ARGS__); \156__ONE_REG(8, __VA_ARGS__); \157__ONE_REG(9, __VA_ARGS__); \158__ONE_REG(10, __VA_ARGS__); \159__ONE_REG(11, __VA_ARGS__); \160__ONE_REG(12, __VA_ARGS__); \161__ONE_REG(13, __VA_ARGS__); \162__ONE_REG(14, __VA_ARGS__); \163__ONE_REG(15, __VA_ARGS__); \164memcpy(p, dwords, 4 * sizedwords); \165p += sizedwords; \166ring->cur = p; \167} while (0)168169#endif /* FD6_PACK_H */170171172