Sony PlayStation2 Study
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1119 lines
42 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __SPS2_DMA_PACKETS_HEADER__
  2. #define __SPS2_DMA_PACKETS_HEADER__
  3. #include "../../../core/base/basicTypes.h"
  4. /** Maximum number allowed, but each channel has its own limitations. */
  5. #define QWC_MAX 65535
  6. #define PACKET_NORMAL 0x00
  7. #define PACKET_UCAB 0x01
  8. #define PACKET_SPR 0x02
  9. #define PACKET2_COUNT_QWC (1 << 16)
  10. /**
  11. * Dmatags use qwc for the number of qwords for they handle.
  12. *
  13. * The dma channel QWC register uses it as the total number of qwords that
  14. * are being sent at a time.
  15. */
  16. typedef struct s_packet_t {
  17. uint32_t qwords;
  18. uint16_t qwc;
  19. uint16_t type;
  20. qword_t * data __attribute__((aligned(64)));
  21. } packet_t;
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /** Allocate a new packet for use, size in quadwords. */
  26. packet_t *packet_init( uint32_t qwords, uint16_t type );
  27. /** Reset the packet quadword counter and zero out data. */
  28. void packet_reset( packet_t *packet );
  29. /** Free the space allocated by packet. */
  30. void packet_free( packet_t *packet );
  31. /** Advances the qwc and returns the current qword count. */
  32. qword_t *packet_increment_qwc(packet_t *packet, uint32_t num );
  33. /** For those that like getters and setters */
  34. static inline qword_t *packet_get_qword( packet_t *packet ){
  35. return (packet)?NULL:packet->data;
  36. };
  37. #ifdef __cplusplus
  38. }
  39. #endif
  40. typedef enum e_packet2_mode{
  41. P2_MODE_NORMAL = 0,
  42. P2_MODE_CHAIN = 1,
  43. }packet2_mode_t;
  44. /** Types of memory mapping. */
  45. typedef enum e_packet2_type{
  46. /** Normal. */
  47. P2_TYPE_NORMAL = 0x00000000,
  48. /** Uncached. */
  49. P2_TYPE_UNCACHED = 0x20000000,
  50. /** Uncached accelerated. */
  51. P2_TYPE_UNCACHED_ACCL = 0x30000000,
  52. /** Scratchpad memory. */
  53. P2_TYPE_SPRAM = 0x70000000
  54. }packet2_type_t;
  55. /** DMA tag types */
  56. typedef enum e_dma_tag_type{
  57. /** Transfers the QWC qword from the ADDR field, clears the Dn_CHCR.STR to 0, and ends transfer. */
  58. P2_DMA_TAG_REFE = 0,
  59. /** Transfers the QWC qword following the tag and reads the succeeding qword as the next tag. */
  60. P2_DMA_TAG_CNT = 1,
  61. /** Transfers the QWC qword following the tag and reads the qword of the ADDR field as the next tag. */
  62. P2_DMA_TAG_NEXT = 2,
  63. /** Transfers the QWC qword from the ADDR field and reads the qword following the tag as the next tag. */
  64. P2_DMA_TAG_REF = 3,
  65. /**
  66. * Transfers the QWC qword from the ADDR field while controlling stalls
  67. * and reads the qword following the tag as the next tag.
  68. * @note Effective only on the VIF1, GIF, and SIF1 channels.
  69. */
  70. P2_DMA_TAG_REFS = 4,
  71. /**
  72. * Transfers the QWC qword following the tag, pushes the next field into
  73. * the Dn_ASR register, and reads the qword of the ADDR field as the next tag.
  74. * @note Effective only on the VIF0, VIF1, and GIF channels.
  75. * Addresses can be pushed up to 2 levels
  76. */
  77. P2_DMA_TAG_CALL = 5,
  78. /**
  79. * Transfers the QWC qword following the tag and reads the
  80. * qword of the field popped from the Dn_ASR register as the
  81. * next tag.
  82. * Transfers the QWC qword following the tag, clears the
  83. * Dn_CHCR.STR to 0, and ends transfer when there is no
  84. * pushed address.
  85. * @note Effective only on the VIF0, VIF1, and GIF channels.
  86. */
  87. P2_DMA_TAG_RET = 6,
  88. /** Transfers the QWC qword following the tag, clears the Dn_CHCR.STR to 0, and ends transfer. */
  89. P2_DMA_TAG_END = 7
  90. } dma_tag_type_t;
  91. /** Destination chain tag. */
  92. typedef struct s_dma_tag{
  93. /** Quadword count. */
  94. uint64_t QWC : 16;
  95. uint64_t PAD : 10;
  96. /**
  97. * Priority Control Enable.
  98. * 00 Nothing performed
  99. * 01 Reserved
  100. * 10 Priority setting disabled (D_PCR.PCE = 0)
  101. * 11 Priority setting enabled (D_PCR.PCE = 1)
  102. */
  103. uint64_t PCE : 2;
  104. /** Tag ID. (look at DmaTagType) */
  105. uint64_t ID : 3;
  106. /**
  107. * Interrupt Request.
  108. * 0 No interrupt request
  109. * 1 Interrupt request at end of packet transfer
  110. */
  111. uint64_t IRQ : 1;
  112. /**
  113. * Address.
  114. * Address of packet or next tag instruction
  115. * (With qword alignment, lower 4 bits become 0.)
  116. */
  117. uint64_t ADDR : 31;
  118. /**
  119. * Memory/SPR Selection.
  120. * 0 Memory address
  121. * 1 SPR address
  122. */
  123. uint64_t SPR : 1;
  124. uint32_t OPT1;
  125. uint32_t OPT2;
  126. }dma_tag_t __attribute__((aligned(16)));
  127. /**
  128. * Unpack modes.
  129. * V2 = 2 dimensions, S = Single = 1 dimension
  130. * _32 = 32 bits of data length.
  131. */
  132. typedef enum e_unpack_mode{
  133. P2_UNPACK_S_32 = 0x00,
  134. P2_UNPACK_S_16 = 0x01,
  135. P2_UNPACK_S_8 = 0x02,
  136. P2_UNPACK_V2_32 = 0x04,
  137. P2_UNPACK_V2_16 = 0x05,
  138. P2_UNPACK_V2_8 = 0x06,
  139. P2_UNPACK_V3_32 = 0x08,
  140. P2_UNPACK_V3_16 = 0x09,
  141. P2_UNPACK_V3_8 = 0x0A,
  142. P2_UNPACK_V4_32 = 0x0C,
  143. P2_UNPACK_V4_16 = 0x0D,
  144. P2_UNPACK_V4_8 = 0x0E,
  145. P2_UNPACK_V4_5 = 0x0F,
  146. }unpack_mode_t;
  147. /** VIF opcodes. */
  148. typedef enum e_vif_opcode{
  149. /**
  150. * No operation.
  151. * No operation is performed.
  152. * NOP is used to adjust the data alignment in the VIF packet.
  153. */
  154. P2_VIF_NOP = 0,
  155. /**
  156. * Sets write recycle.
  157. * STCYCL writes the value of the IMMEDIATE field to the VIFn_CYCLE register.
  158. */
  159. P2_VIF_STCYCL = 1,
  160. /**
  161. * Sets the double buffer offset.
  162. * OFFSET writes the lower 10 bits of the IMMEDIATE field to the VIF1_OFST register.
  163. * At the same time, the DBF flag of the VIF1_STAT register is cleared to 0, and the VIF1_BASE register
  164. * value is set to the VIF1_TOPS. That is, the pointer for the double buffer points to the BASE.
  165. */
  166. P2_VIF_OFFSET = 2,
  167. /**
  168. * Sets the base address of the double buffer.
  169. * BASE writes the lower 10 bits of the IMMEDIATE field to the VIF1_BASE register.
  170. * These bits become the base address of the double buffers.
  171. */
  172. P2_VIF_BASE = 3,
  173. /**
  174. * Sets the data pointer.
  175. * ITOP writes the lower 10 bits of the IMMEDIATE field to the VIFn_ITOPS register.
  176. * This value is read from the VU by the XITOP instruction.
  177. */
  178. P2_VIF_ITOP = 4,
  179. /**
  180. * Sets the addition decompression mode.
  181. * STMOD writes the lower 2 bits of the IMMEDIATE field to the VIFn_MODE register.
  182. * This becomes the addition decompression mode setting.
  183. */
  184. P2_VIF_STMOD = 5,
  185. /**
  186. * Sets the PATH3 mask.
  187. * MSKPATH3 enables/disables transfer processing via the GIF PATH3.
  188. * The setting of this register applies to the next data block or later.
  189. */
  190. P2_VIF_MSKPATH3 = 6,
  191. /**
  192. * Sets the MARK value.
  193. * MARK writes the value of the IMMEDIATE field to the VIFn_MARK register.
  194. * By properly setting the MARK value, it becomes possible to use this value for
  195. * synchronization with the EE Core and debugging.
  196. */
  197. P2_VIF_MARK = 7,
  198. /**
  199. * Waits for end of the microprogram.
  200. * FLUSHE waits for the state in which the microprogram in VU0/VU1 has been ended.
  201. */
  202. P2_VIF_FLUSHE = 16,
  203. /**
  204. * Waits for end of the microprogram.
  205. * FLUSH waits for the state in which transfers to the GIF from PATH1 and PATH2 have been ended after
  206. * end of microprogram in VU1. FLUSH does not wait for the end of the transfer via PATH1 by
  207. * the XGKICK instruction with the E bit.
  208. */
  209. P2_VIF_FLUSH = 17,
  210. /**
  211. * Waits for end of the microprogram.
  212. * FLUSHA waits for the state in which there is no transfer request from PATH3 after the end of micro
  213. * program in VU1 and end of transfer to the GIF from PATH1 and PATH2.
  214. */
  215. P2_VIF_FLUSHA = 18,
  216. /**
  217. * Activates the microprogram.
  218. * MSCAL waits for the end of the microprogram under execution and activates the micro program with the
  219. * value of the IMMEDIATE field as the starting address.
  220. */
  221. P2_VIF_MSCAL = 20,
  222. /**
  223. * Activates the microprogram.
  224. * MSCNT waits for the end of the microprogram under execution and executes the next microprogram from
  225. * the address following the most recently ended one in the PC (program counter).
  226. */
  227. P2_VIF_MSCNT = 23,
  228. /**
  229. * Activates the microprogram.
  230. * MSCALF waits for the end of both the microprogram and the GIF(PATH1/PATH2) transfer and executes
  231. * the microprogram with the value of the IMMEDIATE field as the starting address.
  232. */
  233. P2_VIF_MSCALF = 21,
  234. /**
  235. * Sets the data mask pattern.
  236. * STMASK stores the next 1 word of data in the VIFn_MASK register.
  237. * This data becomes the mask pattern of the write data.
  238. */
  239. P2_VIF_STMASK = 32,
  240. /**
  241. * Sets the filling data.
  242. * STROW stores the following 4 words of data in the VIFn_R0 - VIFn_R3 registers.
  243. * These are used as filling data when decompressed by the VIFcode UNPACK.
  244. */
  245. P2_VIF_STROW = 48,
  246. /**
  247. * Sets the filling data.
  248. * STCOL stores the following 4 words of data in the VIFn_C0 - VIFn_C3 registers.
  249. * These are used as filling data when decompressed by the VIFcode UNPACK.
  250. */
  251. P2_VIF_STCOL = 49,
  252. /**
  253. * Transfers the microprogram.
  254. * MPG waits for the end of the microprogram and transfers the following NUM pieces of 64-bit data.
  255. * (microinstruction code) to the MicroMem address shown by the IMMEDIATE field.
  256. */
  257. P2_VIF_MPG = 74,
  258. /**
  259. * Transfers data to the GIF(GS).
  260. * DIRECT transfers the following IMMEDIATE pieces of 128-bit data to the GS via GIF PATH2. It is
  261. * necessary to put the appropriate GIFtag to the data.
  262. */
  263. P2_VIF_DIRECT = 80,
  264. /**
  265. * Transfers data to the GIF(GS).
  266. * DIRECTHL transfers the following IMMEDIATE pieces of 128-bit data to the GS via GIF PATH2.
  267. * The appropriate GIFtag must be attached to the data.
  268. * Interruption of PATH3 IMAGE mode data does not occur during the data transfer via PATH2 by
  269. * DIRECTHL. Moreover, when the IMAGE mode data is being transferred via PATH3, DIRECTHL stalls
  270. * until the end of the transfer.
  271. */
  272. P2_VIF_DIRECTHL = 81
  273. }vif_opcode_t;
  274. /** VIFCode structure. */
  275. typedef struct s_vif_code{
  276. /** The contents of the IMMEDIATE field vary according to the CMD field. */
  277. uint32_t immediate : 16;
  278. /**
  279. * The NUM field shows the amount of data written to the VU Mem or MicroMem (Data is in 128-bit units
  280. * and microinstruction code is in 64-bit units). When NUM=0, it is considered to be 256.
  281. * Note that it is not the amount of data in the VIF packet. NUM pieces of data can be written even when the
  282. * amount of data in the packet is 0 depending on the CYCLE register setting.
  283. */
  284. uint32_t num : 8;
  285. /**
  286. * The CMD field directs the operation of the VIF, that is, the decompression
  287. * method of the following data.
  288. */
  289. uint32_t cmd : 8;
  290. }vif_code_t;
  291. /**
  292. * DMA data packet.
  293. * Successor of standard packet.
  294. */
  295. typedef struct s_packet2{
  296. /** Maximum number of qwords which was defined in packet2_create(). */
  297. uint16_t max_qwords_count;
  298. /** Type of packet's memory mapping. */
  299. packet2_type_t type;
  300. /** Packet mode. */
  301. packet2_mode_t mode;
  302. /**
  303. * Tag transfer enable.
  304. * Effective only in chain mode.
  305. * If >0 transfer tag is set during packet sending and
  306. * add_dma_tag() (so also every open_tag()) will move buffer by DWORD,
  307. * so remember to align memory!
  308. */
  309. uint8_t tte;
  310. /** Start position of the buffer. */
  311. qword_t * base __attribute__((aligned(64)));
  312. /** Current position of the buffer. */
  313. qword_t * next;
  314. /**
  315. * The buffer position where DMA tag was opened.
  316. * NULL, if no dma tag is open.
  317. */
  318. dma_tag_t * tag_opened_at;
  319. /**
  320. * The buffer position where DIRECT/UNPACK was opened.
  321. * NULL, if no DIRECT/UNPACK is open.
  322. */
  323. vif_code_t * vif_code_opened_at;
  324. }packet2_t;
  325. /** Mask, used in VIF's STMASK opcode. */
  326. typedef union u_vif_mask{
  327. struct{
  328. uint32_t m0 : 2;
  329. uint32_t m1 : 2;
  330. uint32_t m2 : 2;
  331. uint32_t m3 : 2;
  332. uint32_t m4 : 2;
  333. uint32_t m5 : 2;
  334. uint32_t m6 : 2;
  335. uint32_t m7 : 2;
  336. uint32_t m8 : 2;
  337. uint32_t m9 : 2;
  338. uint32_t m10 : 2;
  339. uint32_t m11 : 2;
  340. uint32_t m12 : 2;
  341. uint32_t m13 : 2;
  342. uint32_t m14 : 2;
  343. uint32_t m15 : 2;
  344. };
  345. uint32_t m;
  346. } vif_mask_t;
  347. #ifdef __cplusplus
  348. extern "C"
  349. {
  350. #endif
  351. // ---
  352. // Packet2 management
  353. // ---
  354. /**
  355. * Allocate new packet2.
  356. * @param qwords Maximum data size in qwords (128bit).
  357. * @param type Memory mapping type.
  358. * @param mode Packet mode. Normal or chain.
  359. * @param tte Tag transfer enable.
  360. * Used only for CHAIN mode!
  361. * If >0 transfer tag is set during packet sending and
  362. * add_dma_tag() (so also every open_tag()) will move buffer by DWORD,
  363. * so remember to align memory!
  364. * @returns Pointer to packet2 on success or NULL if memory allocation fail.
  365. */
  366. packet2_t* packet2_create(uint16_t qwords, packet2_type_t type, packet2_mode_t mode, uint8_t tte);
  367. /**
  368. * Create new packet2 with given data pointer.
  369. * @param base Pointer to base (start of buffer).
  370. * @param next Pointer to next (current position of buffer).
  371. * @param qwords Maximum data size in qwords (128bit).
  372. * @param type Memory mapping type.
  373. * @param mode Packet mode. Normal or chain (so also vif/vu).
  374. * @param tte Tag transfer enable.
  375. * Used only for CHAIN mode!
  376. * If >0 transfer tag is set during packet sending and
  377. * add_dma_tag() (so also every open_tag()) will move buffer by DWORD,
  378. * so remember to align memory!
  379. * @returns Pointer to packet2 on success or NULL if memory allocation fail.
  380. */
  381. packet2_t *packet2_create_from(qword_t *base, qword_t *next, uint16_t qwords, packet2_type_t type, packet2_mode_t mode, uint8_t tte);
  382. /**
  383. * Free packet2 memory.
  384. * @param packet2 Pointer to packet2.
  385. */
  386. void packet2_free(packet2_t *packet2);
  387. /**
  388. * Reset packet.
  389. * Move next pointer back to base pointer,
  390. * Make all "openedAt" vars to NULL
  391. * Do memset on data if required.
  392. * @param packet2 Pointer to packet.
  393. * @param clear_mem If >0, data is cleared via memset(). SLOW!
  394. */
  395. void packet2_reset(packet2_t *packet2, uint8_t clear_mem);
  396. /**
  397. * Update current position of packet buffer.
  398. * Useful with drawlib functions.
  399. */
  400. static inline void packet2_update(packet2_t *packet2, qword_t *qw) { packet2->next = qw; };
  401. // ---
  402. // Basic add
  403. // ---
  404. /** Move "next" pointer forward. */
  405. static inline void packet2_advance_next(packet2_t *packet2, uint32_t i ){
  406. packet2->next = (qword_t *)((puint8_t)packet2->next + i);
  407. };
  408. static inline void packet2_add_u128(packet2_t *packet2, const uint128_t val){
  409. *((puint128_t) packet2->next ) = val;
  410. packet2_advance_next(packet2, sizeof(uint128_t));
  411. };
  412. /** @note Alignment alert. Size of dword (1/2) */
  413. static inline void packet2_add_s64(packet2_t *packet2, const int64_t val){
  414. *((pint64_t) packet2->next ) = val;
  415. packet2_advance_next(packet2, sizeof(int64_t));
  416. };
  417. static inline void packet2_add_2x_s64(packet2_t *packet2, const int64_t v1, const int64_t v2){
  418. packet2_add_s64(packet2, v1);
  419. packet2_add_s64(packet2, v2);
  420. };
  421. static inline void packet2_add_s128(packet2_t *packet2, const int128_t val){
  422. *((pint128_t)packet2->next) = val;
  423. packet2_advance_next(packet2, sizeof(int128_t));
  424. };
  425. /** @note Alignment alert. Size of dword (1/2) */
  426. static inline void packet2_add_u64(packet2_t *packet2, const uint64_t val){
  427. *((puint64_t)packet2->next) = val;
  428. packet2_advance_next(packet2, sizeof(uint64_t));
  429. };
  430. /** @note Alignment alert. Size of word (1/4) */
  431. static inline void packet2_add_u32(packet2_t *packet2, const uint32_t val){
  432. *((puint32_t)packet2->next) = val;
  433. packet2_advance_next(packet2, sizeof(uint32_t));
  434. };
  435. /** @note Alignment alert. Size of word (1/4) */
  436. static inline void packet2_add_s32(packet2_t *packet2, const int32_t val){
  437. *((pint32_t)packet2->next) = val;
  438. packet2_advance_next(packet2, sizeof(int32_t));
  439. };
  440. /** @note Alignment alert. Size of word (1/4) */
  441. static inline void packet2_add_float(packet2_t *packet2, const float val){
  442. *((float *)packet2->next) = val;
  443. packet2_advance_next(packet2, sizeof(float));
  444. };
  445. static inline void packet2_add_data(packet2_t *packet2, puint128_t t_data, uint32_t t_size ){
  446. uint32_t i = 0;
  447. for( ; i < t_size; i++) packet2_add_u128( packet2, t_data[i] );
  448. };
  449. /*
  450. ToDo: make according functions to consume various data types
  451. static inline void packet2_add_data(packet2_t *packet2, void *t_data, uint32_t t_size){
  452. uint32_t i;
  453. for (i = 0; i < t_size; i++) packet2_add_u128( packet2,((puint128_t)t_data)[i]);
  454. };
  455. static inline void packet2_add_data(packet2_t *packet2, void *t_data, uint32_t t_size){
  456. uint32_t i;
  457. for (i = 0; i < t_size; i++) packet2_add_u128( packet2,((puint128_t)t_data)[i]);
  458. };
  459. static inline void packet2_add_data(packet2_t *packet2, void *t_data, uint32_t t_size){
  460. uint32_t i;
  461. for (i = 0; i < t_size; i++) packet2_add_u128( packet2,((puint128_t)t_data)[i]);
  462. };
  463. static inline void packet2_add_data(packet2_t *packet2, void *t_data, uint32_t t_size){
  464. uint32_t i;
  465. for (i = 0; i < t_size; i++) packet2_add_u128( packet2,((puint128_t)t_data)[i]);
  466. };
  467. static inline void packet2_add_data(packet2_t *packet2, void *t_data, uint32_t t_size){
  468. uint32_t i;
  469. for (i = 0; i < t_size; i++) packet2_add_u128( packet2,((puint128_t)t_data)[i]);
  470. };
  471. */
  472. /**
  473. * Fill to align to 96bits
  474. */
  475. static inline void packet2_pad96( packet2_t *packet2, const uint32_t val ){
  476. while ((((uint32_t)packet2->next + 4) & 0xf) != 0) packet2_add_u32( packet2, val );
  477. };
  478. /**
  479. * Fill to align to 128bits
  480. */
  481. static inline void packet2_pad128(packet2_t *packet2, const uint32_t val){
  482. while (((uint32_t)packet2->next & 0xf) != 0) packet2_add_u32( packet2, val );
  483. };
  484. // ---
  485. // Other
  486. // ---
  487. /**
  488. * Print data of packet.
  489. * @param packet2 Pointer to packet.
  490. * @param clear_mem Count of qwords, type 0 for all.
  491. */
  492. void packet2_print(packet2_t *packet2, uint32_t qw_count);
  493. /**
  494. * Print amount of qwords of packet.
  495. * @param packet2 Pointer to packet.
  496. */
  497. void packet2_print_qw_count( packet2_t *packet2 );
  498. /** Copy data from b packet into a packet with memcpy() */
  499. void packet2_add(packet2_t *a, packet2_t *b);
  500. /** Returns count of added qwords into packet. */
  501. static inline uint32_t packet2_get_qw_count(packet2_t *packet2) { return ((uint32_t)packet2->next - (uint32_t)packet2->base) >> 4; }
  502. /** True if packet doesnt have even number of quads. */
  503. static inline uint8_t packet2_doesnt_have_even_number_of_quads(packet2_t *packet2) { return ((uint32_t)packet2->next & 0xF) != 0; }
  504. /** True if dma tag is opened. */
  505. static inline uint8_t packet2_is_dma_tag_opened(packet2_t *packet2) { return packet2->tag_opened_at != NULL; }
  506. /** True if DIRECT/UNPACK is opened. */
  507. static inline uint8_t packet2_is_vif_code_opened(packet2_t *packet2) { return packet2->vif_code_opened_at != NULL; }
  508. #ifdef __cplusplus
  509. }
  510. #endif
  511. #ifdef __cplusplus
  512. extern "C"
  513. {
  514. #endif
  515. // ---
  516. // DMA tag management
  517. // ---
  518. /**
  519. * Set dma tag.
  520. * For more details, check description of dma_tag_t.
  521. * @param tag Pointer to DMA tag to set.
  522. * @param qwc Qword count.
  523. * @param pce Priority Control Enable. 0 by default.
  524. * @param id Tag ID.
  525. * @param irq Interrupt Request. False by default.
  526. * @param addr Address.
  527. * @param spr Memory/SPR Selection. False by default.
  528. */
  529. static inline void packet2_chain_set_dma_tag( dma_tag_t *tag, uint32_t qwc, uint32_t pce, dma_tag_type_t id, uint8_t irq, const uint128_t *addr, uint8_t spr){
  530. tag->QWC = qwc;
  531. tag->PCE = pce;
  532. tag->ID = id;
  533. tag->IRQ = irq;
  534. tag->ADDR = (uint64_t)((uint32_t)addr);
  535. tag->SPR = spr;
  536. };
  537. /**
  538. * Add dma tag.
  539. * For more details, check description of dma_tag_t.
  540. * Will move current buffer position by:
  541. * DWORD if packet->tte == true,
  542. * QWORD if packet->tte == false
  543. * @param packet2 Pointer to packet.
  544. * @param qwc Qword count. If you want to use
  545. * packet2_chain_close_tag(), and count qwords
  546. * automatically, set value to PACKET2_COUNT_QWC.
  547. * @param pce Priority Control Enable. 0 by default.
  548. * @param id Tag ID.
  549. * @param irq Interrupt Request. False by default.
  550. * @param addr Address.
  551. * @param spr Memory/SPR Selection. False by default.
  552. */
  553. static inline void packet2_chain_add_dma_tag( packet2_t *packet2, uint32_t qwc, uint32_t pce, dma_tag_type_t id, uint8_t irq, const uint128_t *addr, uint8_t spr){
  554. assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
  555. assert(packet2->tag_opened_at == NULL); // All previous tags are closed.
  556. if( qwc == PACKET2_COUNT_QWC ){
  557. packet2_chain_set_dma_tag((dma_tag_t *)packet2->next, 0, pce, id, irq, addr, spr); // placeholder
  558. packet2->tag_opened_at = (dma_tag_t *)packet2->next;
  559. } else{
  560. packet2_chain_set_dma_tag((dma_tag_t *)packet2->next, qwc, pce, id, irq, addr, spr);
  561. packet2->tag_opened_at = (dma_tag_t *)NULL;
  562. };
  563. if( !packet2->tte ){
  564. packet2_advance_next(packet2, sizeof(dma_tag_t));
  565. } else{
  566. packet2_advance_next(packet2, sizeof(uint64_t));
  567. };
  568. };
  569. /**
  570. * Close dma tag.
  571. * In reality, get back to pointer "tag_opened_at" and fix qwc value.
  572. * @param packet2 Pointer to packet.
  573. */
  574. static inline void packet2_chain_close_tag(packet2_t *packet2){
  575. assert(packet2->tag_opened_at != NULL); // There is opened tag.
  576. assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
  577. packet2->tag_opened_at->QWC = (((uint32_t)packet2->next - (uint32_t)packet2->tag_opened_at) / 16 - 1);
  578. packet2->tag_opened_at = (dma_tag_t *)NULL;
  579. }
  580. // ---
  581. // DMA tags
  582. // ---
  583. /**
  584. * Add CNT tag.
  585. * @note packet2_chain_close_tag() required. Qwords
  586. * are counted automatically.
  587. * For more details, check description of dma_tag_t.
  588. * @param packet2 Pointer to packet.
  589. * @param irq Interrupt Request. False by default.
  590. * @param pce Priority Control Enable. 0 by default.
  591. * @param spr Memory/SPR Selection. False by default.
  592. */
  593. static inline void packet2_chain_open_cnt( packet2_t *packet2, uint8_t irq, uint32_t pce, uint8_t spr ){
  594. packet2_chain_add_dma_tag(packet2, PACKET2_COUNT_QWC, pce, P2_DMA_TAG_CNT, irq, 0, spr);
  595. };
  596. /**
  597. * Add END tag.
  598. * @note packet2_chain_close_tag() required. Qwords
  599. * are counted automatically.
  600. * For more details, check description of dma_tag_t.
  601. * @note Don't forget about close_tag()!
  602. * @param packet2 Pointer to packet.
  603. * @param irq Interrupt Request. False by default.
  604. * @param pce Priority Control Enable. 0 by default.
  605. */
  606. static inline void packet2_chain_open_end( packet2_t *packet2, uint8_t irq, uint32_t pce ){
  607. packet2_chain_add_dma_tag(packet2, PACKET2_COUNT_QWC, pce, P2_DMA_TAG_END, irq, 0, 0);
  608. };
  609. /**
  610. * Add REF tag.
  611. * @note Qwords are NOT counted automatically, so
  612. * there is NO need to use packet2_chain_close_tag();
  613. * For more details, check description of dma_tag_t.
  614. * @param packet2 Pointer to packet.
  615. * @param ref_data Pointer to data.
  616. * @param qw_length Size of data in qwords.
  617. * @param irq Interrupt Request. False by default.
  618. * @param spr Memory/SPR Selection. False by default.
  619. * @param pce Priority Control Enable. 0 by default.
  620. */
  621. static inline void packet2_chain_ref(packet2_t *packet2, const void *ref_data, uint32_t qw_length, uint8_t irq, uint8_t spr, uint32_t pce ){
  622. assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
  623. packet2_chain_add_dma_tag(packet2, qw_length, pce, P2_DMA_TAG_REF, irq, (const uint128_t *)ref_data, spr);
  624. };
  625. /**
  626. * Add NEXT tag.
  627. * @note packet2_chain_close_tag() required. Qwords
  628. * are counted automatically.
  629. * For more details, check description of dma_tag_t.
  630. * @param next_tag Pointer to next tag.
  631. * @param irq Interrupt Request. False by default.
  632. * @param spr Memory/SPR Selection. False by default.
  633. * @param pce Priority Control Enable. 0 by default.
  634. */
  635. static inline void packet2_chain_next(packet2_t *packet2, const dma_tag_t *next_tag, uint8_t irq, uint8_t spr, uint32_t pce){
  636. assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
  637. packet2_chain_add_dma_tag( packet2, PACKET2_COUNT_QWC, pce, P2_DMA_TAG_NEXT, irq, (const uint128_t *)next_tag, spr );
  638. };
  639. /**
  640. * Add REFS tag.
  641. * @note Qwords are NOT counted automatically, so
  642. * there is NO need to use packet2_chain_close_tag();
  643. * For more details, check description of dma_tag_t.
  644. * @param packet2 Pointer to packet.
  645. * @param ref_data Pointer to data.
  646. * @param qw_length Size of data in qwords.
  647. * @param irq Interrupt Request. False by default.
  648. * @param spr Memory/SPR Selection. False by default.
  649. * @param pce Priority Control Enable. 0 by default.
  650. */
  651. static inline void packet2_chain_refs( packet2_t *packet2, const void *ref_data, uint32_t qw_length, uint8_t irq, uint8_t spr, uint32_t pce){
  652. assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
  653. packet2_chain_add_dma_tag(packet2, qw_length, pce, P2_DMA_TAG_REFS, irq, (const uint128_t *)ref_data, spr);
  654. }
  655. /**
  656. * Add REFE tag.
  657. * @note Qwords are NOT counted automatically, so
  658. * there is NO need to use packet2_chain_close_tag();
  659. * For more details, check description of dma_tag_t.
  660. * @param packet2 Pointer to packet.
  661. * @param ref_data Pointer to data.
  662. * @param qw_length Size of data in qwords.
  663. * @param irq Interrupt Request. False by default.
  664. * @param spr Memory/SPR Selection. False by default.
  665. * @param pce Priority Control Enable. 0 by default.
  666. */
  667. static inline void packet2_chain_refe( packet2_t *packet2, const void *ref_data, uint32_t qw_length, uint8_t irq, uint8_t spr, uint32_t pce ){
  668. assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
  669. packet2_chain_add_dma_tag(packet2, qw_length, pce, P2_DMA_TAG_REFE, irq, (const uint128_t *)ref_data, spr);
  670. };
  671. /**
  672. * Add CALL tag.
  673. * @note packet2_chain_close_tag() required. Qwords
  674. * are counted automatically.
  675. * For more details, check description of dma_tag_t.
  676. * @param packet2 Pointer to packet.
  677. * @param next_tag Pointer to next tag.
  678. * @param irq Interrupt Request. False by default.
  679. * @param spr Memory/SPR Selection. False by default.
  680. * @param pce Priority Control Enable. 0 by default.
  681. */
  682. static inline void packet2_chain_call( packet2_t *packet2, const void *next_tag, uint8_t irq, uint8_t spr, uint32_t pce ){
  683. assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
  684. packet2_chain_add_dma_tag(packet2, PACKET2_COUNT_QWC, pce, P2_DMA_TAG_CALL, irq, (const uint128_t *)next_tag, spr);
  685. };
  686. /**
  687. * Add RET tag.
  688. * @note packet2_chain_close_tag() required. Qwords
  689. * are counted automatically.
  690. * For more details, check description of dma_tag_t.
  691. * @param packet2 Pointer to packet.
  692. * @param irq Interrupt Request. False by default.
  693. * @param pce Priority Control Enable. 0 by default.
  694. */
  695. static inline void packet2_chain_ret(packet2_t *packet2, uint8_t irq, uint32_t pce){
  696. packet2_chain_add_dma_tag(packet2, PACKET2_COUNT_QWC, pce, P2_DMA_TAG_RET, irq, 0, 0);
  697. };
  698. #ifdef __cplusplus
  699. }
  700. #endif
  701. #define MAKE_VIF_CODE(_immediate, _num, _cmd, _irq) ((uint32_t)(_immediate) | ((uint32_t)(_num) << 16) | ((uint32_t)(_cmd) << 24) | ((uint32_t)(_irq) << 31))
  702. #ifdef __cplusplus
  703. extern "C"
  704. {
  705. #endif
  706. /**
  707. * Add UNPACK VIF opcode.
  708. * @note packet2_vif_close_unpack() required. Qwords
  709. * are counted automatically.
  710. * For more details, check description of vif_code_t.
  711. * @param packet2 Pointer to packet.
  712. * @param mode Unpack mode
  713. * @param vuAddr Memory address (divided by 16).
  714. * @param dblBuffered (VIF1 only)
  715. * 1 - Adds VIF1_TOPS register to ADDR
  716. * 0 - Does not use VIF1_TOPS register.
  717. * @param masked Is masked
  718. * @param usigned
  719. * 1 - Unsigned - Decompress by padding 0 to the upper field
  720. * 0 - Signed - Decompress by sign extension
  721. * @param irq Interrupt Request. False by default.
  722. */
  723. static inline void packet2_vif_open_unpack(packet2_t *packet2, unpack_mode_t mode, uint32_t vuAddr, uint8_t dblBuffered, uint8_t masked, uint8_t usigned, uint8_t irq){
  724. assert(packet2->vif_code_opened_at == NULL); // All previous UNPACK/DIRECT are closed.
  725. packet2->vif_code_opened_at = (vif_code_t *)packet2->next;
  726. packet2_add_u32( packet2, MAKE_VIF_CODE(vuAddr | ((uint32_t)usigned << 14) | ((uint32_t)dblBuffered << 15), 0, mode | ((uint32_t)masked << 4) | 0x60, irq) );
  727. };
  728. /**
  729. * Close UNPACK manually.
  730. * In reality, get back to pointer "vif_code_opened_at" and
  731. * fix num value with qwords counted from last packet2_vif_open_unpack().
  732. * @param packet2 Pointer to packet.
  733. * @param unpack_num Amount of data written to the VU Mem (qwords) or MicroMem (dwords).
  734. * 256 is max value!
  735. */
  736. static inline void packet2_vif_close_unpack_manual(packet2_t *packet2, uint32_t unpack_num){
  737. assert(packet2->vif_code_opened_at != NULL); // There is open UNPACK/DIRECT.
  738. assert(((uint32_t)packet2->next & 0x3) == 0); // Make sure we're u32 aligned
  739. assert((packet2->vif_code_opened_at->cmd & 0x60) == 0x60); // It was UNPACK
  740. assert(unpack_num <= 256);
  741. packet2->vif_code_opened_at->num = (unpack_num == 256) ? 0 : unpack_num;
  742. packet2->vif_code_opened_at = (vif_code_t *)NULL;
  743. }
  744. /**
  745. * Close UNPACK automatically.
  746. * In reality, get back to pointer "vif_code_opened_at" and
  747. * fix num value with qwords counted from last packet2_vif_open_unpack().
  748. * @param packet2 Pointer to packet.
  749. * @param wl WL Value (look at STCYCL)
  750. * @param cl CL Value (look at STCYCL)
  751. * @returns Unpacked qwords count
  752. */
  753. uint32_t packet2_vif_close_unpack_auto(packet2_t *packet2, uint32_t wl, uint32_t cl);
  754. /**
  755. * Add DIRECT VIF opcode.
  756. * @note Direct must be closed via
  757. * packet2_vif_close_direct_manual() or
  758. * packet2_vif_close : "memory"
  759. */
  760. static inline void packet2_vif_open_direct(packet2_t *packet2, uint8_t irq){
  761. assert(packet2->vif_code_opened_at == NULL); // All previous UNPACK/DIRECT are closed.
  762. packet2->vif_code_opened_at = (vif_code_t *)packet2->next;
  763. packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_DIRECT, irq));
  764. };
  765. /**
  766. * Close DIRECT manually.
  767. * In reality, get back to pointer "vif_code_opened_at" and
  768. * fix immediate value with given value.
  769. * @param packet2 Pointer to packet.
  770. * @param qwords Qwords count.
  771. */
  772. static inline void packet2_vif_close_direct_manual(packet2_t *packet2, uint32_t qwords){
  773. assert(packet2->vif_code_opened_at != NULL); // There is open UNPACK/DIRECT.
  774. assert((((uint32_t)packet2->next - ((uint32_t)packet2->vif_code_opened_at + 4)) & 0xF) == 0);
  775. packet2->vif_code_opened_at->immediate = qwords;
  776. packet2->vif_code_opened_at = (vif_code_t *)NULL;
  777. };
  778. /**
  779. * Close DIRECT automatically.
  780. * In reality, get back to pointer "vif_code_opened_at" and
  781. * fix immediate value with qwords counted from last packet2_vif_open_direct().
  782. * @param packet2 Pointer to packet.
  783. */
  784. static inline void packet2_vif_close_direct_auto(packet2_t *packet2){
  785. return packet2_vif_close_direct_manual(packet2, ((uint32_t)packet2->next - ((uint32_t)packet2->vif_code_opened_at + 4)) >> 4);
  786. };
  787. /**
  788. * Add NOP VIF opcode.
  789. * @note Alignment alert. Size of word (1/4).
  790. * For more details, check description of VIFOpcode.
  791. * @param packet2 Pointer to packet.
  792. * @param irq Interrupt Request. False by default.
  793. */
  794. static inline void packet2_vif_nop(packet2_t *packet2, uint8_t irq){
  795. packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_NOP, irq));
  796. };
  797. /**
  798. * Fill with NOP VIF opcode to align to 96bits
  799. * @param packet2 Pointer to packet.
  800. */
  801. static inline void packet2_vif_pad96(packet2_t *packet2){
  802. packet2_pad96(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_NOP, 0));
  803. };
  804. /**
  805. * Fill with NOP VIF opcode to align to 128bits
  806. * @param packet2 Pointer to packet.
  807. */
  808. static inline void packet2_vif_pad128(packet2_t *packet2){
  809. packet2_pad128(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_NOP, 0));
  810. };
  811. /**
  812. * Add MPG VIF opcode.
  813. * @note Alignment alert. Size of word (1/4).
  814. * For more details, check description of VIFOpcode.
  815. * @param packet2 Pointer to packet.
  816. * @param num Number of 64-bit data.
  817. * @param addr Address.
  818. * @param irq Interrupt Request. False by default.
  819. */
  820. static inline void packet2_vif_mpg(packet2_t *packet2, uint32_t num, uint32_t addr, uint8_t irq ){
  821. packet2_add_u32(packet2, MAKE_VIF_CODE(addr, num, P2_VIF_MPG, irq));
  822. };
  823. /**
  824. * Add STCYCL VIF opcode.
  825. * @note Alignment alert. Size of word (1/4).
  826. * For more details, check description of VIFOpcode.
  827. * @param packet2 Pointer to packet.
  828. * @param wl WL field.
  829. * @param cl CL field.
  830. * @param irq Interrupt Request. False by default.
  831. */
  832. static inline void packet2_vif_stcycl(packet2_t *packet2, uint32_t wl, uint32_t cl, uint8_t irq){
  833. packet2_add_u32(packet2, MAKE_VIF_CODE(cl | (wl << 8), 0, P2_VIF_STCYCL, irq));
  834. };
  835. /**
  836. * Add OFFSET VIF opcode.
  837. * @note Alignment alert. Size of word (1/4).
  838. * For more details, check description of VIFOpcode.
  839. * @param packet2 Pointer to packet.
  840. * @param offset Offset. BASE+OFFSET will be the address of second buffer.
  841. * @param irq Interrupt Request. False by default.
  842. */
  843. static inline void packet2_vif_offset( packet2_t *packet2, uint32_t offset, uint8_t irq ){
  844. packet2_add_u32(packet2, MAKE_VIF_CODE(offset, 0, P2_VIF_OFFSET, irq));
  845. };
  846. /**
  847. * Add BASE VIF opcode.
  848. * @note Alignment alert. Size of word (1/4).
  849. * For more details, check description of VIFOpcode.
  850. * @param packet2 Pointer to packet.
  851. * @param base Base address of double buffer.
  852. * @param irq Interrupt Request. False by default.
  853. */
  854. static inline void packet2_vif_base( packet2_t *packet2, uint32_t base, uint8_t irq ){
  855. packet2_add_u32(packet2, MAKE_VIF_CODE(base, 0, P2_VIF_BASE, irq));
  856. };
  857. /**
  858. * Add FLUSH VIF opcode.
  859. * @note Alignment alert. Size of word (1/4).
  860. * For more details, check description of VIFOpcode.
  861. * @param packet2 Pointer to packet.
  862. * @param irq Interrupt Request. False by default.
  863. */
  864. static inline void packet2_vif_flush( packet2_t *packet2, uint8_t irq ){
  865. packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_FLUSH, irq));
  866. };
  867. /**
  868. * Add MSCAL VIF opcode.
  869. * @note Alignment alert. Size of word (1/4).
  870. * For more details, check description of VIFOpcode.
  871. * @param packet2 Pointer to packet.
  872. * @param addr Starting address.
  873. * @param irq Interrupt Request. False by default.
  874. */
  875. static inline void packet2_vif_mscal( packet2_t *packet2, uint32_t addr, uint8_t irq ){
  876. packet2_add_u32(packet2, MAKE_VIF_CODE(addr, 0, P2_VIF_MSCAL, irq));
  877. };
  878. /**
  879. * Add MSCNT VIF opcode.
  880. * @note Alignment alert. Size of word (1/4).
  881. * For more details, check description of VIFOpcode.
  882. * @param packet2 Pointer to packet.
  883. * @param irq Interrupt Request. False by default.
  884. */
  885. static inline void packet2_vif_mscnt( packet2_t *packet2, uint8_t irq ){
  886. packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_MSCNT, irq));
  887. };
  888. /**
  889. * Add ITOP VIF opcode.
  890. * @note Alignment alert. Size of word (1/4).
  891. * For more details, check description of VIFOpcode.
  892. * @param packet2 Pointer to packet.
  893. * @param itops Value for VU XITOP instruction.
  894. * @param irq Interrupt Request. False by default.
  895. */
  896. static inline void packet2_vif_itop(packet2_t *packet2, uint32_t itops, uint8_t irq){
  897. packet2_add_u32(packet2, MAKE_VIF_CODE(itops, 0, P2_VIF_ITOP, irq));
  898. };
  899. /**
  900. * Add MSKPATH3 VIF opcode.
  901. * @note Alignment alert. Size of word (1/4).
  902. * For more details, check description of VIFOpcode.
  903. * @param packet2 Pointer to packet.
  904. * @param mode Decompression mode.
  905. * @param irq Interrupt Request. False by default.
  906. */
  907. static inline void packet2_vif_stmod(packet2_t *packet2, uint32_t mode, uint8_t irq){
  908. packet2_add_u32(packet2, MAKE_VIF_CODE(mode, 0, P2_VIF_STMOD, irq));
  909. };
  910. /**
  911. * Add MSKPATH3 VIF opcode.
  912. * @note Alignment alert. Size of word (1/4).
  913. * For more details, check description of VIFOpcode.
  914. * @param packet2 Pointer to packet.
  915. * @param mask Mask.
  916. * @param irq Interrupt Request. False by default.
  917. */
  918. static inline void packet2_vif_mskpath3(packet2_t *packet2, uint32_t mask, uint8_t irq){
  919. packet2_add_u32(packet2, MAKE_VIF_CODE(mask, 0, P2_VIF_MSKPATH3, irq));
  920. };
  921. /**
  922. * Add MARK VIF opcode.
  923. * @note Alignment alert. Size of word (1/4).
  924. * For more details, check description of VIFOpcode.
  925. * @param packet2 Pointer to packet.
  926. * @param value Value.
  927. * @param irq Interrupt Request. False by default.
  928. */
  929. static inline void packet2_vif_mark(packet2_t *packet2, uint32_t value, uint8_t irq){
  930. packet2_add_u32(packet2, MAKE_VIF_CODE(value, 0, P2_VIF_MARK, irq));
  931. };
  932. /**
  933. * Add FLUSHE VIF opcode.
  934. * @note Alignment alert. Size of word (1/4).
  935. * For more details, check description of VIFOpcode.
  936. * @param packet2 Pointer to packet.
  937. * @param irq Interrupt Request. False by default.
  938. */
  939. static inline void packet2_vif_flushe(packet2_t *packet2, uint8_t irq){
  940. packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_FLUSHE, irq));
  941. };
  942. /**
  943. * Add FLUSHA VIF opcode.
  944. * @note Alignment alert. Size of word (1/4).
  945. * For more details, check description of VIFOpcode.
  946. * @param packet2 Pointer to packet.
  947. * @param irq Interrupt Request. False by default.
  948. */
  949. static inline void packet2_vif_flusha(packet2_t *packet2, uint8_t irq){
  950. packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_FLUSHA, irq));
  951. };
  952. /**
  953. * Add MSCALF VIF opcode.
  954. * @note Alignment alert. Size of word (1/4).
  955. * For more details, check description of VIFOpcode.
  956. * @param packet2 Pointer to packet.
  957. * @param addr Address.
  958. * @param irq Interrupt Request. False by default.
  959. */
  960. static inline void packet2_vif_mscalf(packet2_t *packet2, uint32_t addr, uint32_t irq){
  961. packet2_add_u32(packet2, MAKE_VIF_CODE(addr, 0, P2_VIF_MSCALF, irq));
  962. };
  963. /**
  964. * Add STMASK VIF opcode.
  965. * @note Alignment alert. Size of dword (1/2).
  966. * For more details, check description of VIFOpcode.
  967. * @param packet2 Pointer to packet.
  968. * @param mask Mask.
  969. * @param irq Interrupt Request. False by default.
  970. */
  971. static inline void packet2_vif_stmask(packet2_t *packet2, vif_mask_t mask, uint8_t irq){
  972. packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_STMASK, irq));
  973. packet2_add_u32(packet2, mask.m);
  974. };
  975. /**
  976. * Add STROW VIF opcode.
  977. * @note Alignment alert. Size of 5 x word (1+1/4).
  978. * For more details, check description of VIFOpcode.
  979. * @param packet2 Pointer to packet.
  980. * @param row_arr Row array.
  981. * @param irq Interrupt Request. False by default.
  982. */
  983. static inline void packet2_vif_strow(packet2_t *packet2, const uint32_t *row_arr, uint8_t irq){
  984. packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_STROW, irq));
  985. packet2_add_u32(packet2, row_arr[0]);
  986. packet2_add_u32(packet2, row_arr[1]);
  987. packet2_add_u32(packet2, row_arr[2]);
  988. packet2_add_u32(packet2, row_arr[3]);
  989. };
  990. /**
  991. * Add STCOL VIF opcode.
  992. * @note Alignment alert. Size of 5 x word (1+1/4).
  993. * For more details, check description of VIFOpcode.
  994. * @param packet2 Pointer to packet.
  995. * @param col_arr Column array.
  996. * @param irq Interrupt Request. False by default.
  997. */
  998. static inline void packet2_vif_stcol(packet2_t *packet2, const uint32_t *col_arr, uint8_t irq ){
  999. packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_STCOL, irq));
  1000. packet2_add_u32(packet2, col_arr[0]);
  1001. packet2_add_u32(packet2, col_arr[1]);
  1002. packet2_add_u32(packet2, col_arr[2]);
  1003. packet2_add_u32(packet2, col_arr[3]);
  1004. };
  1005. /**
  1006. * Add VU micro program into packet2.
  1007. * Packet2 MODE for micro program upload: Chain
  1008. * @param dest VU destination address (divided by 16).
  1009. * @param start Start address.
  1010. * @param end End address.
  1011. */
  1012. void packet2_vif_add_micro_program(packet2_t *packet2, uint32_t dest, uint32_t *start, uint32_t *end);
  1013. #ifdef __cplusplus
  1014. }
  1015. #endif
  1016. #endif