Path: blob/21.2-virgl/src/freedreno/common/freedreno_pm4.h
4565 views
/*1* Copyright (C) 2012-2018 Rob Clark <[email protected]>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*22* Authors:23* Rob Clark <[email protected]>24*/2526#ifndef FREEDRENO_PM4_H_27#define FREEDRENO_PM4_H_2829#include <stdint.h>3031#ifdef __cplusplus32extern "C" {33#endif3435#define CP_TYPE0_PKT 0x0000000036#define CP_TYPE2_PKT 0x8000000037#define CP_TYPE3_PKT 0xc000000038#define CP_TYPE4_PKT 0x4000000039#define CP_TYPE7_PKT 0x700000004041/*42* Helpers for pm4 pkt header building/parsing:43*/4445static inline unsigned46pm4_odd_parity_bit(unsigned val)47{48/* See: http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel49* note that we want odd parity so 0x6996 is inverted.50*/51val ^= val >> 16;52val ^= val >> 8;53val ^= val >> 4;54val &= 0xf;55return (~0x6996 >> val) & 1;56}5758static inline uint32_t59pm4_pkt0_hdr(uint16_t regindx, uint16_t cnt)60{61return CP_TYPE0_PKT | ((cnt - 1) << 16) | (regindx & 0x7fff);62}6364static inline uint32_t65pm4_pkt3_hdr(uint8_t opcode, uint16_t cnt)66{67return CP_TYPE3_PKT | ((cnt - 1) << 16) | ((opcode & 0xff) << 8);68}6970static inline uint32_t71pm4_pkt4_hdr(uint16_t regindx, uint16_t cnt)72{73return CP_TYPE4_PKT | cnt | (pm4_odd_parity_bit(cnt) << 7) |74((regindx & 0x3ffff) << 8) |75((pm4_odd_parity_bit(regindx) << 27));76}7778static inline uint32_t79pm4_pkt7_hdr(uint8_t opcode, uint16_t cnt)80{81return CP_TYPE7_PKT | cnt | (pm4_odd_parity_bit(cnt) << 15) |82((opcode & 0x7f) << 16) |83((pm4_odd_parity_bit(opcode) << 23));84}8586/*87* Helpers for packet parsing:88*/8990#define pkt_is_type0(pkt) (((pkt)&0XC0000000) == CP_TYPE0_PKT)91#define type0_pkt_size(pkt) ((((pkt) >> 16) & 0x3FFF) + 1)92#define type0_pkt_offset(pkt) ((pkt)&0x7FFF)9394#define pkt_is_type2(pkt) ((pkt) == CP_TYPE2_PKT)9596#define pkt_is_type3(pkt) \97((((pkt)&0xC0000000) == CP_TYPE3_PKT) && (((pkt)&0x80FE) == 0))9899#define cp_type3_opcode(pkt) (((pkt) >> 8) & 0xFF)100#define type3_pkt_size(pkt) ((((pkt) >> 16) & 0x3FFF) + 1)101102static inline uint103pm4_calc_odd_parity_bit(uint val)104{105return (0x9669 >> (0xf & ((val) ^ ((val) >> 4) ^ ((val) >> 8) ^106((val) >> 12) ^ ((val) >> 16) ^ ((val) >> 20) ^107((val) >> 24) ^ ((val) >> 28)))) &1081;109}110111#define pkt_is_type4(pkt) \112((((pkt)&0xF0000000) == CP_TYPE4_PKT) && \113((((pkt) >> 27) & 0x1) == \114pm4_calc_odd_parity_bit(type4_pkt_offset(pkt))) && \115((((pkt) >> 7) & 0x1) == pm4_calc_odd_parity_bit(type4_pkt_size(pkt))))116117#define type4_pkt_offset(pkt) (((pkt) >> 8) & 0x7FFFF)118#define type4_pkt_size(pkt) ((pkt)&0x7F)119120#define pkt_is_type7(pkt) \121((((pkt)&0xF0000000) == CP_TYPE7_PKT) && (((pkt)&0x0F000000) == 0) && \122((((pkt) >> 23) & 0x1) == \123pm4_calc_odd_parity_bit(cp_type7_opcode(pkt))) && \124((((pkt) >> 15) & 0x1) == pm4_calc_odd_parity_bit(type7_pkt_size(pkt))))125126#define cp_type7_opcode(pkt) (((pkt) >> 16) & 0x7F)127#define type7_pkt_size(pkt) ((pkt)&0x3FFF)128129#ifdef __cplusplus130} /* end of extern "C" */131#endif132133#endif /* FREEDRENO_PM4_H_ */134135136