13f012e29Smrg/*
23f012e29Smrg * Copyright © 2014 Broadcom
33f012e29Smrg *
43f012e29Smrg * Permission is hereby granted, free of charge, to any person obtaining a
53f012e29Smrg * copy of this software and associated documentation files (the "Software"),
63f012e29Smrg * to deal in the Software without restriction, including without limitation
73f012e29Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
83f012e29Smrg * and/or sell copies of the Software, and to permit persons to whom the
93f012e29Smrg * Software is furnished to do so, subject to the following conditions:
103f012e29Smrg *
113f012e29Smrg * The above copyright notice and this permission notice (including the next
123f012e29Smrg * paragraph) shall be included in all copies or substantial portions of the
133f012e29Smrg * Software.
143f012e29Smrg *
153f012e29Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
163f012e29Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
173f012e29Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
183f012e29Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
193f012e29Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
203f012e29Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
213f012e29Smrg * IN THE SOFTWARE.
223f012e29Smrg */
233f012e29Smrg
243f012e29Smrg#ifndef VC4_QPU_DEFINES_H
253f012e29Smrg#define VC4_QPU_DEFINES_H
263f012e29Smrg
273f012e29Smrgenum qpu_op_add {
283f012e29Smrg        QPU_A_NOP,
293f012e29Smrg        QPU_A_FADD,
303f012e29Smrg        QPU_A_FSUB,
313f012e29Smrg        QPU_A_FMIN,
323f012e29Smrg        QPU_A_FMAX,
333f012e29Smrg        QPU_A_FMINABS,
343f012e29Smrg        QPU_A_FMAXABS,
353f012e29Smrg        QPU_A_FTOI,
363f012e29Smrg        QPU_A_ITOF,
373f012e29Smrg        QPU_A_ADD = 12,
383f012e29Smrg        QPU_A_SUB,
393f012e29Smrg        QPU_A_SHR,
403f012e29Smrg        QPU_A_ASR,
413f012e29Smrg        QPU_A_ROR,
423f012e29Smrg        QPU_A_SHL,
433f012e29Smrg        QPU_A_MIN,
443f012e29Smrg        QPU_A_MAX,
453f012e29Smrg        QPU_A_AND,
463f012e29Smrg        QPU_A_OR,
473f012e29Smrg        QPU_A_XOR,
483f012e29Smrg        QPU_A_NOT,
493f012e29Smrg        QPU_A_CLZ,
503f012e29Smrg        QPU_A_V8ADDS = 30,
513f012e29Smrg        QPU_A_V8SUBS = 31,
523f012e29Smrg};
533f012e29Smrg
543f012e29Smrgenum qpu_op_mul {
553f012e29Smrg        QPU_M_NOP,
563f012e29Smrg        QPU_M_FMUL,
573f012e29Smrg        QPU_M_MUL24,
583f012e29Smrg        QPU_M_V8MULD,
593f012e29Smrg        QPU_M_V8MIN,
603f012e29Smrg        QPU_M_V8MAX,
613f012e29Smrg        QPU_M_V8ADDS,
623f012e29Smrg        QPU_M_V8SUBS,
633f012e29Smrg};
643f012e29Smrg
653f012e29Smrgenum qpu_raddr {
663f012e29Smrg        QPU_R_FRAG_PAYLOAD_ZW = 15, /* W for A file, Z for B file */
673f012e29Smrg        /* 0-31 are the plain regfile a or b fields */
683f012e29Smrg        QPU_R_UNIF = 32,
693f012e29Smrg        QPU_R_VARY = 35,
703f012e29Smrg        QPU_R_ELEM_QPU = 38,
713f012e29Smrg        QPU_R_NOP,
723f012e29Smrg        QPU_R_XY_PIXEL_COORD = 41,
733f012e29Smrg        QPU_R_MS_REV_FLAGS = 42,
743f012e29Smrg        QPU_R_VPM = 48,
753f012e29Smrg        QPU_R_VPM_LD_BUSY,
763f012e29Smrg        QPU_R_VPM_LD_WAIT,
773f012e29Smrg        QPU_R_MUTEX_ACQUIRE,
783f012e29Smrg};
793f012e29Smrg
803f012e29Smrgenum qpu_waddr {
813f012e29Smrg        /* 0-31 are the plain regfile a or b fields */
823f012e29Smrg        QPU_W_ACC0 = 32, /* aka r0 */
833f012e29Smrg        QPU_W_ACC1,
843f012e29Smrg        QPU_W_ACC2,
853f012e29Smrg        QPU_W_ACC3,
863f012e29Smrg        QPU_W_TMU_NOSWAP,
873f012e29Smrg        QPU_W_ACC5,
883f012e29Smrg        QPU_W_HOST_INT,
893f012e29Smrg        QPU_W_NOP,
903f012e29Smrg        QPU_W_UNIFORMS_ADDRESS,
913f012e29Smrg        QPU_W_QUAD_XY, /* X for regfile a, Y for regfile b */
923f012e29Smrg        QPU_W_MS_FLAGS = 42,
933f012e29Smrg        QPU_W_REV_FLAG = 42,
943f012e29Smrg        QPU_W_TLB_STENCIL_SETUP = 43,
953f012e29Smrg        QPU_W_TLB_Z,
963f012e29Smrg        QPU_W_TLB_COLOR_MS,
973f012e29Smrg        QPU_W_TLB_COLOR_ALL,
983f012e29Smrg        QPU_W_TLB_ALPHA_MASK,
993f012e29Smrg        QPU_W_VPM,
1003f012e29Smrg        QPU_W_VPMVCD_SETUP, /* LD for regfile a, ST for regfile b */
1013f012e29Smrg        QPU_W_VPM_ADDR, /* LD for regfile a, ST for regfile b */
1023f012e29Smrg        QPU_W_MUTEX_RELEASE,
1033f012e29Smrg        QPU_W_SFU_RECIP,
1043f012e29Smrg        QPU_W_SFU_RECIPSQRT,
1053f012e29Smrg        QPU_W_SFU_EXP,
1063f012e29Smrg        QPU_W_SFU_LOG,
1073f012e29Smrg        QPU_W_TMU0_S,
1083f012e29Smrg        QPU_W_TMU0_T,
1093f012e29Smrg        QPU_W_TMU0_R,
1103f012e29Smrg        QPU_W_TMU0_B,
1113f012e29Smrg        QPU_W_TMU1_S,
1123f012e29Smrg        QPU_W_TMU1_T,
1133f012e29Smrg        QPU_W_TMU1_R,
1143f012e29Smrg        QPU_W_TMU1_B,
1153f012e29Smrg};
1163f012e29Smrg
1173f012e29Smrgenum qpu_sig_bits {
1183f012e29Smrg        QPU_SIG_SW_BREAKPOINT,
1193f012e29Smrg        QPU_SIG_NONE,
1203f012e29Smrg        QPU_SIG_THREAD_SWITCH,
1213f012e29Smrg        QPU_SIG_PROG_END,
1223f012e29Smrg        QPU_SIG_WAIT_FOR_SCOREBOARD,
1233f012e29Smrg        QPU_SIG_SCOREBOARD_UNLOCK,
1243f012e29Smrg        QPU_SIG_LAST_THREAD_SWITCH,
1253f012e29Smrg        QPU_SIG_COVERAGE_LOAD,
1263f012e29Smrg        QPU_SIG_COLOR_LOAD,
1273f012e29Smrg        QPU_SIG_COLOR_LOAD_END,
1283f012e29Smrg        QPU_SIG_LOAD_TMU0,
1293f012e29Smrg        QPU_SIG_LOAD_TMU1,
1303f012e29Smrg        QPU_SIG_ALPHA_MASK_LOAD,
1313f012e29Smrg        QPU_SIG_SMALL_IMM,
1323f012e29Smrg        QPU_SIG_LOAD_IMM,
1333f012e29Smrg        QPU_SIG_BRANCH
1343f012e29Smrg};
1353f012e29Smrg
1363f012e29Smrgenum qpu_mux {
1373f012e29Smrg        /* hardware mux values */
1383f012e29Smrg        QPU_MUX_R0,
1393f012e29Smrg        QPU_MUX_R1,
1403f012e29Smrg        QPU_MUX_R2,
1413f012e29Smrg        QPU_MUX_R3,
1423f012e29Smrg        QPU_MUX_R4,
1433f012e29Smrg        QPU_MUX_R5,
1443f012e29Smrg        QPU_MUX_A,
1453f012e29Smrg        QPU_MUX_B,
1463f012e29Smrg
1473f012e29Smrg        /**
1483f012e29Smrg         * Non-hardware mux value, stores a small immediate field to be
1493f012e29Smrg         * programmed into raddr_b in the qpu_reg.index.
1503f012e29Smrg         */
1513f012e29Smrg        QPU_MUX_SMALL_IMM,
1523f012e29Smrg};
1533f012e29Smrg
1543f012e29Smrgenum qpu_cond {
1553f012e29Smrg        QPU_COND_NEVER,
1563f012e29Smrg        QPU_COND_ALWAYS,
1573f012e29Smrg        QPU_COND_ZS,
1583f012e29Smrg        QPU_COND_ZC,
1593f012e29Smrg        QPU_COND_NS,
1603f012e29Smrg        QPU_COND_NC,
1613f012e29Smrg        QPU_COND_CS,
1623f012e29Smrg        QPU_COND_CC,
1633f012e29Smrg};
1643f012e29Smrg
1653f012e29Smrgenum qpu_pack_mul {
1663f012e29Smrg        QPU_PACK_MUL_NOP,
1673f012e29Smrg        QPU_PACK_MUL_8888 = 3, /* replicated to each 8 bits of the 32-bit dst. */
1683f012e29Smrg        QPU_PACK_MUL_8A,
1693f012e29Smrg        QPU_PACK_MUL_8B,
1703f012e29Smrg        QPU_PACK_MUL_8C,
1713f012e29Smrg        QPU_PACK_MUL_8D,
1723f012e29Smrg};
1733f012e29Smrg
1743f012e29Smrgenum qpu_pack_a {
1753f012e29Smrg        QPU_PACK_A_NOP,
1763f012e29Smrg        /* convert to 16 bit float if float input, or to int16. */
1773f012e29Smrg        QPU_PACK_A_16A,
1783f012e29Smrg        QPU_PACK_A_16B,
1793f012e29Smrg        /* replicated to each 8 bits of the 32-bit dst. */
1803f012e29Smrg        QPU_PACK_A_8888,
1813f012e29Smrg        /* Convert to 8-bit unsigned int. */
1823f012e29Smrg        QPU_PACK_A_8A,
1833f012e29Smrg        QPU_PACK_A_8B,
1843f012e29Smrg        QPU_PACK_A_8C,
1853f012e29Smrg        QPU_PACK_A_8D,
1863f012e29Smrg
1873f012e29Smrg        /* Saturating variants of the previous instructions. */
1883f012e29Smrg        QPU_PACK_A_32_SAT, /* int-only */
1893f012e29Smrg        QPU_PACK_A_16A_SAT, /* int or float */
1903f012e29Smrg        QPU_PACK_A_16B_SAT,
1913f012e29Smrg        QPU_PACK_A_8888_SAT,
1923f012e29Smrg        QPU_PACK_A_8A_SAT,
1933f012e29Smrg        QPU_PACK_A_8B_SAT,
1943f012e29Smrg        QPU_PACK_A_8C_SAT,
1953f012e29Smrg        QPU_PACK_A_8D_SAT,
1963f012e29Smrg};
1973f012e29Smrg
1983f012e29Smrgenum qpu_unpack {
1993f012e29Smrg        QPU_UNPACK_NOP,
2003f012e29Smrg        QPU_UNPACK_16A,
2013f012e29Smrg        QPU_UNPACK_16B,
2023f012e29Smrg        QPU_UNPACK_8D_REP,
2033f012e29Smrg        QPU_UNPACK_8A,
2043f012e29Smrg        QPU_UNPACK_8B,
2053f012e29Smrg        QPU_UNPACK_8C,
2063f012e29Smrg        QPU_UNPACK_8D,
2073f012e29Smrg};
2083f012e29Smrg
2093f012e29Smrg#define QPU_MASK(high, low) ((((uint64_t)1<<((high)-(low)+1))-1)<<(low))
2103f012e29Smrg/* Using the GNU statement expression extension */
2113f012e29Smrg#define QPU_SET_FIELD(value, field)                                       \
2123f012e29Smrg        ({                                                                \
2133f012e29Smrg                uint64_t fieldval = (uint64_t)(value) << field ## _SHIFT; \
2143f012e29Smrg                assert((fieldval & ~ field ## _MASK) == 0);               \
2153f012e29Smrg                fieldval & field ## _MASK;                                \
2163f012e29Smrg         })
2173f012e29Smrg
2183f012e29Smrg#define QPU_GET_FIELD(word, field) ((uint32_t)(((word)  & field ## _MASK) >> field ## _SHIFT))
2193f012e29Smrg
2203f012e29Smrg#define QPU_UPDATE_FIELD(inst, value, field)                              \
2213f012e29Smrg        (((inst) & ~(field ## _MASK)) | QPU_SET_FIELD(value, field))
2223f012e29Smrg
2233f012e29Smrg#define QPU_SIG_SHIFT                   60
2243f012e29Smrg#define QPU_SIG_MASK                    QPU_MASK(63, 60)
2253f012e29Smrg
2263f012e29Smrg#define QPU_UNPACK_SHIFT                57
2273f012e29Smrg#define QPU_UNPACK_MASK                 QPU_MASK(59, 57)
2283f012e29Smrg
2293f012e29Smrg/**
2303f012e29Smrg * If set, the pack field means PACK_MUL or R4 packing, instead of normal
2313f012e29Smrg * regfile a packing.
2323f012e29Smrg */
2333f012e29Smrg#define QPU_PM                          ((uint64_t)1 << 56)
2343f012e29Smrg
2353f012e29Smrg#define QPU_PACK_SHIFT                  52
2363f012e29Smrg#define QPU_PACK_MASK                   QPU_MASK(55, 52)
2373f012e29Smrg
2383f012e29Smrg#define QPU_COND_ADD_SHIFT              49
2393f012e29Smrg#define QPU_COND_ADD_MASK               QPU_MASK(51, 49)
2403f012e29Smrg#define QPU_COND_MUL_SHIFT              46
2413f012e29Smrg#define QPU_COND_MUL_MASK               QPU_MASK(48, 46)
2423f012e29Smrg
2433f012e29Smrg#define QPU_SF                          ((uint64_t)1 << 45)
2443f012e29Smrg
2453f012e29Smrg#define QPU_WADDR_ADD_SHIFT             38
2463f012e29Smrg#define QPU_WADDR_ADD_MASK              QPU_MASK(43, 38)
2473f012e29Smrg#define QPU_WADDR_MUL_SHIFT             32
2483f012e29Smrg#define QPU_WADDR_MUL_MASK              QPU_MASK(37, 32)
2493f012e29Smrg
2503f012e29Smrg#define QPU_OP_MUL_SHIFT                29
2513f012e29Smrg#define QPU_OP_MUL_MASK                 QPU_MASK(31, 29)
2523f012e29Smrg
2533f012e29Smrg#define QPU_RADDR_A_SHIFT               18
2543f012e29Smrg#define QPU_RADDR_A_MASK                QPU_MASK(23, 18)
2553f012e29Smrg#define QPU_RADDR_B_SHIFT               12
2563f012e29Smrg#define QPU_RADDR_B_MASK                QPU_MASK(17, 12)
2573f012e29Smrg#define QPU_SMALL_IMM_SHIFT             12
2583f012e29Smrg#define QPU_SMALL_IMM_MASK              QPU_MASK(17, 12)
2593f012e29Smrg
2603f012e29Smrg#define QPU_ADD_A_SHIFT                 9
2613f012e29Smrg#define QPU_ADD_A_MASK                  QPU_MASK(11, 9)
2623f012e29Smrg#define QPU_ADD_B_SHIFT                 6
2633f012e29Smrg#define QPU_ADD_B_MASK                  QPU_MASK(8, 6)
2643f012e29Smrg#define QPU_MUL_A_SHIFT                 3
2653f012e29Smrg#define QPU_MUL_A_MASK                  QPU_MASK(5, 3)
2663f012e29Smrg#define QPU_MUL_B_SHIFT                 0
2673f012e29Smrg#define QPU_MUL_B_MASK                  QPU_MASK(2, 0)
2683f012e29Smrg
2693f012e29Smrg#define QPU_WS                          ((uint64_t)1 << 44)
2703f012e29Smrg
2713f012e29Smrg#define QPU_OP_ADD_SHIFT                24
2723f012e29Smrg#define QPU_OP_ADD_MASK                 QPU_MASK(28, 24)
2733f012e29Smrg
2743f012e29Smrg#endif /* VC4_QPU_DEFINES_H */
275