|
|
#ifndef __SPS2_DMA_PACKETS_HEADER__
#define __SPS2_DMA_PACKETS_HEADER__
#include "../../../core/base/basicTypes.h"
/** Maximum number allowed, but each channel has its own limitations. */#define QWC_MAX 65535
#define PACKET_NORMAL 0x00
#define PACKET_UCAB 0x01
#define PACKET_SPR 0x02
#define PACKET2_COUNT_QWC (1 << 16)
/**
* Dmatags use qwc for the number of qwords for they handle. * * The dma channel QWC register uses it as the total number of qwords that * are being sent at a time. */typedef struct s_packet_t { uint32_t qwords; uint16_t qwc; uint16_t type; qword_t * data __attribute__((aligned(64)));} packet_t;
#ifdef __cplusplus
extern "C" {#endif
/** Allocate a new packet for use, size in quadwords. */ packet_t *packet_init( uint32_t qwords, uint16_t type );
/** Reset the packet quadword counter and zero out data. */ void packet_reset( packet_t *packet );
/** Free the space allocated by packet. */ void packet_free( packet_t *packet );
/** Advances the qwc and returns the current qword count. */ qword_t *packet_increment_qwc(packet_t *packet, uint32_t num );
/** For those that like getters and setters */ static inline qword_t *packet_get_qword( packet_t *packet ){ return (packet)?NULL:packet->data; };
#ifdef __cplusplus
}#endif
typedef enum e_packet2_mode{ P2_MODE_NORMAL = 0, P2_MODE_CHAIN = 1,}packet2_mode_t;
/** Types of memory mapping. */typedef enum e_packet2_type{ /** Normal. */ P2_TYPE_NORMAL = 0x00000000, /** Uncached. */ P2_TYPE_UNCACHED = 0x20000000, /** Uncached accelerated. */ P2_TYPE_UNCACHED_ACCL = 0x30000000, /** Scratchpad memory. */ P2_TYPE_SPRAM = 0x70000000}packet2_type_t;
/** DMA tag types */typedef enum e_dma_tag_type{ /** Transfers the QWC qword from the ADDR field, clears the Dn_CHCR.STR to 0, and ends transfer. */ P2_DMA_TAG_REFE = 0, /** Transfers the QWC qword following the tag and reads the succeeding qword as the next tag. */ P2_DMA_TAG_CNT = 1, /** Transfers the QWC qword following the tag and reads the qword of the ADDR field as the next tag. */ P2_DMA_TAG_NEXT = 2, /** Transfers the QWC qword from the ADDR field and reads the qword following the tag as the next tag. */ P2_DMA_TAG_REF = 3, /**
* Transfers the QWC qword from the ADDR field while controlling stalls * and reads the qword following the tag as the next tag. * @note Effective only on the VIF1, GIF, and SIF1 channels. */ P2_DMA_TAG_REFS = 4, /**
* Transfers the QWC qword following the tag, pushes the next field into * the Dn_ASR register, and reads the qword of the ADDR field as the next tag. * @note Effective only on the VIF0, VIF1, and GIF channels. * Addresses can be pushed up to 2 levels */ P2_DMA_TAG_CALL = 5, /**
* Transfers the QWC qword following the tag and reads the * qword of the field popped from the Dn_ASR register as the * next tag. * Transfers the QWC qword following the tag, clears the * Dn_CHCR.STR to 0, and ends transfer when there is no * pushed address. * @note Effective only on the VIF0, VIF1, and GIF channels. */ P2_DMA_TAG_RET = 6, /** Transfers the QWC qword following the tag, clears the Dn_CHCR.STR to 0, and ends transfer. */ P2_DMA_TAG_END = 7} dma_tag_type_t;
/** Destination chain tag. */typedef struct s_dma_tag{ /** Quadword count. */ uint64_t QWC : 16; uint64_t PAD : 10; /**
* Priority Control Enable. * 00 Nothing performed * 01 Reserved * 10 Priority setting disabled (D_PCR.PCE = 0) * 11 Priority setting enabled (D_PCR.PCE = 1) */ uint64_t PCE : 2; /** Tag ID. (look at DmaTagType) */ uint64_t ID : 3; /**
* Interrupt Request. * 0 No interrupt request * 1 Interrupt request at end of packet transfer */ uint64_t IRQ : 1; /**
* Address. * Address of packet or next tag instruction * (With qword alignment, lower 4 bits become 0.) */ uint64_t ADDR : 31; /**
* Memory/SPR Selection. * 0 Memory address * 1 SPR address */ uint64_t SPR : 1;
uint32_t OPT1; uint32_t OPT2;}dma_tag_t __attribute__((aligned(16)));
/**
* Unpack modes. * V2 = 2 dimensions, S = Single = 1 dimension * _32 = 32 bits of data length. */typedef enum e_unpack_mode{ P2_UNPACK_S_32 = 0x00, P2_UNPACK_S_16 = 0x01, P2_UNPACK_S_8 = 0x02, P2_UNPACK_V2_32 = 0x04, P2_UNPACK_V2_16 = 0x05, P2_UNPACK_V2_8 = 0x06, P2_UNPACK_V3_32 = 0x08, P2_UNPACK_V3_16 = 0x09, P2_UNPACK_V3_8 = 0x0A, P2_UNPACK_V4_32 = 0x0C, P2_UNPACK_V4_16 = 0x0D, P2_UNPACK_V4_8 = 0x0E, P2_UNPACK_V4_5 = 0x0F,}unpack_mode_t;
/** VIF opcodes. */typedef enum e_vif_opcode{ /**
* No operation. * No operation is performed. * NOP is used to adjust the data alignment in the VIF packet. */ P2_VIF_NOP = 0, /**
* Sets write recycle. * STCYCL writes the value of the IMMEDIATE field to the VIFn_CYCLE register. */ P2_VIF_STCYCL = 1, /**
* Sets the double buffer offset. * OFFSET writes the lower 10 bits of the IMMEDIATE field to the VIF1_OFST register. * At the same time, the DBF flag of the VIF1_STAT register is cleared to 0, and the VIF1_BASE register * value is set to the VIF1_TOPS. That is, the pointer for the double buffer points to the BASE. */ P2_VIF_OFFSET = 2, /**
* Sets the base address of the double buffer. * BASE writes the lower 10 bits of the IMMEDIATE field to the VIF1_BASE register. * These bits become the base address of the double buffers. */ P2_VIF_BASE = 3, /**
* Sets the data pointer. * ITOP writes the lower 10 bits of the IMMEDIATE field to the VIFn_ITOPS register. * This value is read from the VU by the XITOP instruction. */ P2_VIF_ITOP = 4, /**
* Sets the addition decompression mode. * STMOD writes the lower 2 bits of the IMMEDIATE field to the VIFn_MODE register. * This becomes the addition decompression mode setting. */ P2_VIF_STMOD = 5, /**
* Sets the PATH3 mask. * MSKPATH3 enables/disables transfer processing via the GIF PATH3. * The setting of this register applies to the next data block or later. */ P2_VIF_MSKPATH3 = 6, /**
* Sets the MARK value. * MARK writes the value of the IMMEDIATE field to the VIFn_MARK register. * By properly setting the MARK value, it becomes possible to use this value for * synchronization with the EE Core and debugging. */ P2_VIF_MARK = 7, /**
* Waits for end of the microprogram. * FLUSHE waits for the state in which the microprogram in VU0/VU1 has been ended. */ P2_VIF_FLUSHE = 16, /**
* Waits for end of the microprogram. * FLUSH waits for the state in which transfers to the GIF from PATH1 and PATH2 have been ended after * end of microprogram in VU1. FLUSH does not wait for the end of the transfer via PATH1 by * the XGKICK instruction with the E bit. */ P2_VIF_FLUSH = 17, /**
* Waits for end of the microprogram. * FLUSHA waits for the state in which there is no transfer request from PATH3 after the end of micro * program in VU1 and end of transfer to the GIF from PATH1 and PATH2. */ P2_VIF_FLUSHA = 18, /**
* Activates the microprogram. * MSCAL waits for the end of the microprogram under execution and activates the micro program with the * value of the IMMEDIATE field as the starting address. */ P2_VIF_MSCAL = 20, /**
* Activates the microprogram. * MSCNT waits for the end of the microprogram under execution and executes the next microprogram from * the address following the most recently ended one in the PC (program counter). */ P2_VIF_MSCNT = 23, /**
* Activates the microprogram. * MSCALF waits for the end of both the microprogram and the GIF(PATH1/PATH2) transfer and executes * the microprogram with the value of the IMMEDIATE field as the starting address. */ P2_VIF_MSCALF = 21, /**
* Sets the data mask pattern. * STMASK stores the next 1 word of data in the VIFn_MASK register. * This data becomes the mask pattern of the write data. */ P2_VIF_STMASK = 32, /**
* Sets the filling data. * STROW stores the following 4 words of data in the VIFn_R0 - VIFn_R3 registers. * These are used as filling data when decompressed by the VIFcode UNPACK. */ P2_VIF_STROW = 48, /**
* Sets the filling data. * STCOL stores the following 4 words of data in the VIFn_C0 - VIFn_C3 registers. * These are used as filling data when decompressed by the VIFcode UNPACK. */ P2_VIF_STCOL = 49, /**
* Transfers the microprogram. * MPG waits for the end of the microprogram and transfers the following NUM pieces of 64-bit data. * (microinstruction code) to the MicroMem address shown by the IMMEDIATE field. */ P2_VIF_MPG = 74, /**
* Transfers data to the GIF(GS). * DIRECT transfers the following IMMEDIATE pieces of 128-bit data to the GS via GIF PATH2. It is * necessary to put the appropriate GIFtag to the data. */ P2_VIF_DIRECT = 80, /**
* Transfers data to the GIF(GS). * DIRECTHL transfers the following IMMEDIATE pieces of 128-bit data to the GS via GIF PATH2. * The appropriate GIFtag must be attached to the data. * Interruption of PATH3 IMAGE mode data does not occur during the data transfer via PATH2 by * DIRECTHL. Moreover, when the IMAGE mode data is being transferred via PATH3, DIRECTHL stalls * until the end of the transfer. */ P2_VIF_DIRECTHL = 81}vif_opcode_t;
/** VIFCode structure. */typedef struct s_vif_code{ /** The contents of the IMMEDIATE field vary according to the CMD field. */ uint32_t immediate : 16; /**
* The NUM field shows the amount of data written to the VU Mem or MicroMem (Data is in 128-bit units * and microinstruction code is in 64-bit units). When NUM=0, it is considered to be 256. * Note that it is not the amount of data in the VIF packet. NUM pieces of data can be written even when the * amount of data in the packet is 0 depending on the CYCLE register setting. */ uint32_t num : 8; /**
* The CMD field directs the operation of the VIF, that is, the decompression * method of the following data. */ uint32_t cmd : 8;}vif_code_t;
/**
* DMA data packet. * Successor of standard packet. */typedef struct s_packet2{ /** Maximum number of qwords which was defined in packet2_create(). */ uint16_t max_qwords_count; /** Type of packet's memory mapping. */ packet2_type_t type; /** Packet mode. */ packet2_mode_t mode; /**
* Tag transfer enable. * Effective only in chain mode. * If >0 transfer tag is set during packet sending and * add_dma_tag() (so also every open_tag()) will move buffer by DWORD, * so remember to align memory! */ uint8_t tte; /** Start position of the buffer. */ qword_t * base __attribute__((aligned(64))); /** Current position of the buffer. */ qword_t * next; /**
* The buffer position where DMA tag was opened. * NULL, if no dma tag is open. */ dma_tag_t * tag_opened_at; /**
* The buffer position where DIRECT/UNPACK was opened. * NULL, if no DIRECT/UNPACK is open. */ vif_code_t * vif_code_opened_at;}packet2_t;
/** Mask, used in VIF's STMASK opcode. */typedef union u_vif_mask{ struct{ uint32_t m0 : 2; uint32_t m1 : 2; uint32_t m2 : 2; uint32_t m3 : 2; uint32_t m4 : 2; uint32_t m5 : 2; uint32_t m6 : 2; uint32_t m7 : 2; uint32_t m8 : 2; uint32_t m9 : 2; uint32_t m10 : 2; uint32_t m11 : 2; uint32_t m12 : 2; uint32_t m13 : 2; uint32_t m14 : 2; uint32_t m15 : 2; }; uint32_t m;} vif_mask_t;
#ifdef __cplusplus
extern "C" {#endif
// ---
// Packet2 management
// ---
/**
* Allocate new packet2. * @param qwords Maximum data size in qwords (128bit). * @param type Memory mapping type. * @param mode Packet mode. Normal or chain. * @param tte Tag transfer enable. * Used only for CHAIN mode! * If >0 transfer tag is set during packet sending and * add_dma_tag() (so also every open_tag()) will move buffer by DWORD, * so remember to align memory! * @returns Pointer to packet2 on success or NULL if memory allocation fail. */ packet2_t* packet2_create(uint16_t qwords, packet2_type_t type, packet2_mode_t mode, uint8_t tte);
/**
* Create new packet2 with given data pointer. * @param base Pointer to base (start of buffer). * @param next Pointer to next (current position of buffer). * @param qwords Maximum data size in qwords (128bit). * @param type Memory mapping type. * @param mode Packet mode. Normal or chain (so also vif/vu). * @param tte Tag transfer enable. * Used only for CHAIN mode! * If >0 transfer tag is set during packet sending and * add_dma_tag() (so also every open_tag()) will move buffer by DWORD, * so remember to align memory! * @returns Pointer to packet2 on success or NULL if memory allocation fail. */ 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);
/**
* Free packet2 memory. * @param packet2 Pointer to packet2. */ void packet2_free(packet2_t *packet2);
/**
* Reset packet. * Move next pointer back to base pointer, * Make all "openedAt" vars to NULL * Do memset on data if required. * @param packet2 Pointer to packet. * @param clear_mem If >0, data is cleared via memset(). SLOW! */ void packet2_reset(packet2_t *packet2, uint8_t clear_mem);
/**
* Update current position of packet buffer. * Useful with drawlib functions. */ static inline void packet2_update(packet2_t *packet2, qword_t *qw) { packet2->next = qw; };
// ---
// Basic add
// ---
/** Move "next" pointer forward. */ static inline void packet2_advance_next(packet2_t *packet2, uint32_t i ){ packet2->next = (qword_t *)((puint8_t)packet2->next + i); };
static inline void packet2_add_u128(packet2_t *packet2, const uint128_t val){ *((puint128_t) packet2->next ) = val; packet2_advance_next(packet2, sizeof(uint128_t)); };
/** @note Alignment alert. Size of dword (1/2) */ static inline void packet2_add_s64(packet2_t *packet2, const int64_t val){ *((pint64_t) packet2->next ) = val; packet2_advance_next(packet2, sizeof(int64_t)); };
static inline void packet2_add_2x_s64(packet2_t *packet2, const int64_t v1, const int64_t v2){ packet2_add_s64(packet2, v1); packet2_add_s64(packet2, v2); };
static inline void packet2_add_s128(packet2_t *packet2, const int128_t val){ *((pint128_t)packet2->next) = val; packet2_advance_next(packet2, sizeof(int128_t)); };
/** @note Alignment alert. Size of dword (1/2) */ static inline void packet2_add_u64(packet2_t *packet2, const uint64_t val){ *((puint64_t)packet2->next) = val; packet2_advance_next(packet2, sizeof(uint64_t)); };
/** @note Alignment alert. Size of word (1/4) */ static inline void packet2_add_u32(packet2_t *packet2, const uint32_t val){ *((puint32_t)packet2->next) = val; packet2_advance_next(packet2, sizeof(uint32_t)); };
/** @note Alignment alert. Size of word (1/4) */ static inline void packet2_add_s32(packet2_t *packet2, const int32_t val){ *((pint32_t)packet2->next) = val; packet2_advance_next(packet2, sizeof(int32_t)); };
/** @note Alignment alert. Size of word (1/4) */ static inline void packet2_add_float(packet2_t *packet2, const float val){ *((float *)packet2->next) = val; packet2_advance_next(packet2, sizeof(float)); };
static inline void packet2_add_data(packet2_t *packet2, puint128_t t_data, uint32_t t_size ){ uint32_t i = 0; for( ; i < t_size; i++) packet2_add_u128( packet2, t_data[i] ); }; /*
ToDo: make according functions to consume various data types static inline void packet2_add_data(packet2_t *packet2, void *t_data, uint32_t t_size){ uint32_t i; for (i = 0; i < t_size; i++) packet2_add_u128( packet2,((puint128_t)t_data)[i]); }; static inline void packet2_add_data(packet2_t *packet2, void *t_data, uint32_t t_size){ uint32_t i; for (i = 0; i < t_size; i++) packet2_add_u128( packet2,((puint128_t)t_data)[i]); }; static inline void packet2_add_data(packet2_t *packet2, void *t_data, uint32_t t_size){ uint32_t i; for (i = 0; i < t_size; i++) packet2_add_u128( packet2,((puint128_t)t_data)[i]); }; static inline void packet2_add_data(packet2_t *packet2, void *t_data, uint32_t t_size){ uint32_t i; for (i = 0; i < t_size; i++) packet2_add_u128( packet2,((puint128_t)t_data)[i]); }; static inline void packet2_add_data(packet2_t *packet2, void *t_data, uint32_t t_size){ uint32_t i; for (i = 0; i < t_size; i++) packet2_add_u128( packet2,((puint128_t)t_data)[i]); }; */
/**
* Fill to align to 96bits */ static inline void packet2_pad96( packet2_t *packet2, const uint32_t val ){ while ((((uint32_t)packet2->next + 4) & 0xf) != 0) packet2_add_u32( packet2, val ); };
/**
* Fill to align to 128bits */ static inline void packet2_pad128(packet2_t *packet2, const uint32_t val){ while (((uint32_t)packet2->next & 0xf) != 0) packet2_add_u32( packet2, val ); };
// ---
// Other
// ---
/**
* Print data of packet. * @param packet2 Pointer to packet. * @param clear_mem Count of qwords, type 0 for all. */ void packet2_print(packet2_t *packet2, uint32_t qw_count);
/**
* Print amount of qwords of packet. * @param packet2 Pointer to packet. */ void packet2_print_qw_count( packet2_t *packet2 );
/** Copy data from b packet into a packet with memcpy() */ void packet2_add(packet2_t *a, packet2_t *b);
/** Returns count of added qwords into packet. */ static inline uint32_t packet2_get_qw_count(packet2_t *packet2) { return ((uint32_t)packet2->next - (uint32_t)packet2->base) >> 4; }
/** True if packet doesnt have even number of quads. */ static inline uint8_t packet2_doesnt_have_even_number_of_quads(packet2_t *packet2) { return ((uint32_t)packet2->next & 0xF) != 0; }
/** True if dma tag is opened. */ static inline uint8_t packet2_is_dma_tag_opened(packet2_t *packet2) { return packet2->tag_opened_at != NULL; }
/** True if DIRECT/UNPACK is opened. */ static inline uint8_t packet2_is_vif_code_opened(packet2_t *packet2) { return packet2->vif_code_opened_at != NULL; }
#ifdef __cplusplus
}#endif
#ifdef __cplusplus
extern "C" {#endif
// ---
// DMA tag management
// ---
/**
* Set dma tag. * For more details, check description of dma_tag_t. * @param tag Pointer to DMA tag to set. * @param qwc Qword count. * @param pce Priority Control Enable. 0 by default. * @param id Tag ID. * @param irq Interrupt Request. False by default. * @param addr Address. * @param spr Memory/SPR Selection. False by default. */ 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){ tag->QWC = qwc; tag->PCE = pce; tag->ID = id; tag->IRQ = irq; tag->ADDR = (uint64_t)((uint32_t)addr); tag->SPR = spr; };
/**
* Add dma tag. * For more details, check description of dma_tag_t. * Will move current buffer position by: * DWORD if packet->tte == true, * QWORD if packet->tte == false * @param packet2 Pointer to packet. * @param qwc Qword count. If you want to use * packet2_chain_close_tag(), and count qwords * automatically, set value to PACKET2_COUNT_QWC. * @param pce Priority Control Enable. 0 by default. * @param id Tag ID. * @param irq Interrupt Request. False by default. * @param addr Address. * @param spr Memory/SPR Selection. False by default. */ 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){ assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
assert(packet2->tag_opened_at == NULL); // All previous tags are closed.
if( qwc == PACKET2_COUNT_QWC ){ packet2_chain_set_dma_tag((dma_tag_t *)packet2->next, 0, pce, id, irq, addr, spr); // placeholder
packet2->tag_opened_at = (dma_tag_t *)packet2->next; } else{ packet2_chain_set_dma_tag((dma_tag_t *)packet2->next, qwc, pce, id, irq, addr, spr); packet2->tag_opened_at = (dma_tag_t *)NULL; }; if( !packet2->tte ){ packet2_advance_next(packet2, sizeof(dma_tag_t)); } else{ packet2_advance_next(packet2, sizeof(uint64_t)); }; };
/**
* Close dma tag. * In reality, get back to pointer "tag_opened_at" and fix qwc value. * @param packet2 Pointer to packet. */ static inline void packet2_chain_close_tag(packet2_t *packet2){ assert(packet2->tag_opened_at != NULL); // There is opened tag.
assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
packet2->tag_opened_at->QWC = (((uint32_t)packet2->next - (uint32_t)packet2->tag_opened_at) / 16 - 1); packet2->tag_opened_at = (dma_tag_t *)NULL; }
// ---
// DMA tags
// ---
/**
* Add CNT tag. * @note packet2_chain_close_tag() required. Qwords * are counted automatically. * For more details, check description of dma_tag_t. * @param packet2 Pointer to packet. * @param irq Interrupt Request. False by default. * @param pce Priority Control Enable. 0 by default. * @param spr Memory/SPR Selection. False by default. */ static inline void packet2_chain_open_cnt( packet2_t *packet2, uint8_t irq, uint32_t pce, uint8_t spr ){ packet2_chain_add_dma_tag(packet2, PACKET2_COUNT_QWC, pce, P2_DMA_TAG_CNT, irq, 0, spr); };
/**
* Add END tag. * @note packet2_chain_close_tag() required. Qwords * are counted automatically. * For more details, check description of dma_tag_t. * @note Don't forget about close_tag()! * @param packet2 Pointer to packet. * @param irq Interrupt Request. False by default. * @param pce Priority Control Enable. 0 by default. */ static inline void packet2_chain_open_end( packet2_t *packet2, uint8_t irq, uint32_t pce ){ packet2_chain_add_dma_tag(packet2, PACKET2_COUNT_QWC, pce, P2_DMA_TAG_END, irq, 0, 0); };
/**
* Add REF tag. * @note Qwords are NOT counted automatically, so * there is NO need to use packet2_chain_close_tag(); * For more details, check description of dma_tag_t. * @param packet2 Pointer to packet. * @param ref_data Pointer to data. * @param qw_length Size of data in qwords. * @param irq Interrupt Request. False by default. * @param spr Memory/SPR Selection. False by default. * @param pce Priority Control Enable. 0 by default. */ 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 ){ assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
packet2_chain_add_dma_tag(packet2, qw_length, pce, P2_DMA_TAG_REF, irq, (const uint128_t *)ref_data, spr); };
/**
* Add NEXT tag. * @note packet2_chain_close_tag() required. Qwords * are counted automatically. * For more details, check description of dma_tag_t. * @param next_tag Pointer to next tag. * @param irq Interrupt Request. False by default. * @param spr Memory/SPR Selection. False by default. * @param pce Priority Control Enable. 0 by default. */ static inline void packet2_chain_next(packet2_t *packet2, const dma_tag_t *next_tag, uint8_t irq, uint8_t spr, uint32_t pce){ assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
packet2_chain_add_dma_tag( packet2, PACKET2_COUNT_QWC, pce, P2_DMA_TAG_NEXT, irq, (const uint128_t *)next_tag, spr ); };
/**
* Add REFS tag. * @note Qwords are NOT counted automatically, so * there is NO need to use packet2_chain_close_tag(); * For more details, check description of dma_tag_t. * @param packet2 Pointer to packet. * @param ref_data Pointer to data. * @param qw_length Size of data in qwords. * @param irq Interrupt Request. False by default. * @param spr Memory/SPR Selection. False by default. * @param pce Priority Control Enable. 0 by default. */ 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){ assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
packet2_chain_add_dma_tag(packet2, qw_length, pce, P2_DMA_TAG_REFS, irq, (const uint128_t *)ref_data, spr); }
/**
* Add REFE tag. * @note Qwords are NOT counted automatically, so * there is NO need to use packet2_chain_close_tag(); * For more details, check description of dma_tag_t. * @param packet2 Pointer to packet. * @param ref_data Pointer to data. * @param qw_length Size of data in qwords. * @param irq Interrupt Request. False by default. * @param spr Memory/SPR Selection. False by default. * @param pce Priority Control Enable. 0 by default. */ 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 ){ assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
packet2_chain_add_dma_tag(packet2, qw_length, pce, P2_DMA_TAG_REFE, irq, (const uint128_t *)ref_data, spr); };
/**
* Add CALL tag. * @note packet2_chain_close_tag() required. Qwords * are counted automatically. * For more details, check description of dma_tag_t. * @param packet2 Pointer to packet. * @param next_tag Pointer to next tag. * @param irq Interrupt Request. False by default. * @param spr Memory/SPR Selection. False by default. * @param pce Priority Control Enable. 0 by default. */ static inline void packet2_chain_call( packet2_t *packet2, const void *next_tag, uint8_t irq, uint8_t spr, uint32_t pce ){ assert(((uint32_t)packet2->next & 0xF) == 0); // Free space in packet is aligned properly.
packet2_chain_add_dma_tag(packet2, PACKET2_COUNT_QWC, pce, P2_DMA_TAG_CALL, irq, (const uint128_t *)next_tag, spr); };
/**
* Add RET tag. * @note packet2_chain_close_tag() required. Qwords * are counted automatically. * For more details, check description of dma_tag_t. * @param packet2 Pointer to packet. * @param irq Interrupt Request. False by default. * @param pce Priority Control Enable. 0 by default. */ static inline void packet2_chain_ret(packet2_t *packet2, uint8_t irq, uint32_t pce){ packet2_chain_add_dma_tag(packet2, PACKET2_COUNT_QWC, pce, P2_DMA_TAG_RET, irq, 0, 0); };
#ifdef __cplusplus
}#endif
#define MAKE_VIF_CODE(_immediate, _num, _cmd, _irq) ((uint32_t)(_immediate) | ((uint32_t)(_num) << 16) | ((uint32_t)(_cmd) << 24) | ((uint32_t)(_irq) << 31))
#ifdef __cplusplus
extern "C" {#endif
/**
* Add UNPACK VIF opcode. * @note packet2_vif_close_unpack() required. Qwords * are counted automatically. * For more details, check description of vif_code_t. * @param packet2 Pointer to packet. * @param mode Unpack mode * @param vuAddr Memory address (divided by 16). * @param dblBuffered (VIF1 only) * 1 - Adds VIF1_TOPS register to ADDR * 0 - Does not use VIF1_TOPS register. * @param masked Is masked * @param usigned * 1 - Unsigned - Decompress by padding 0 to the upper field * 0 - Signed - Decompress by sign extension * @param irq Interrupt Request. False by default. */ 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){ assert(packet2->vif_code_opened_at == NULL); // All previous UNPACK/DIRECT are closed.
packet2->vif_code_opened_at = (vif_code_t *)packet2->next; packet2_add_u32( packet2, MAKE_VIF_CODE(vuAddr | ((uint32_t)usigned << 14) | ((uint32_t)dblBuffered << 15), 0, mode | ((uint32_t)masked << 4) | 0x60, irq) ); };
/**
* Close UNPACK manually. * In reality, get back to pointer "vif_code_opened_at" and * fix num value with qwords counted from last packet2_vif_open_unpack(). * @param packet2 Pointer to packet. * @param unpack_num Amount of data written to the VU Mem (qwords) or MicroMem (dwords). * 256 is max value! */ static inline void packet2_vif_close_unpack_manual(packet2_t *packet2, uint32_t unpack_num){ assert(packet2->vif_code_opened_at != NULL); // There is open UNPACK/DIRECT.
assert(((uint32_t)packet2->next & 0x3) == 0); // Make sure we're u32 aligned
assert((packet2->vif_code_opened_at->cmd & 0x60) == 0x60); // It was UNPACK
assert(unpack_num <= 256); packet2->vif_code_opened_at->num = (unpack_num == 256) ? 0 : unpack_num; packet2->vif_code_opened_at = (vif_code_t *)NULL; }
/**
* Close UNPACK automatically. * In reality, get back to pointer "vif_code_opened_at" and * fix num value with qwords counted from last packet2_vif_open_unpack(). * @param packet2 Pointer to packet. * @param wl WL Value (look at STCYCL) * @param cl CL Value (look at STCYCL) * @returns Unpacked qwords count */ uint32_t packet2_vif_close_unpack_auto(packet2_t *packet2, uint32_t wl, uint32_t cl);
/**
* Add DIRECT VIF opcode. * @note Direct must be closed via * packet2_vif_close_direct_manual() or * packet2_vif_close : "memory" */ static inline void packet2_vif_open_direct(packet2_t *packet2, uint8_t irq){ assert(packet2->vif_code_opened_at == NULL); // All previous UNPACK/DIRECT are closed.
packet2->vif_code_opened_at = (vif_code_t *)packet2->next; packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_DIRECT, irq)); };
/**
* Close DIRECT manually. * In reality, get back to pointer "vif_code_opened_at" and * fix immediate value with given value. * @param packet2 Pointer to packet. * @param qwords Qwords count. */ static inline void packet2_vif_close_direct_manual(packet2_t *packet2, uint32_t qwords){ assert(packet2->vif_code_opened_at != NULL); // There is open UNPACK/DIRECT.
assert((((uint32_t)packet2->next - ((uint32_t)packet2->vif_code_opened_at + 4)) & 0xF) == 0); packet2->vif_code_opened_at->immediate = qwords; packet2->vif_code_opened_at = (vif_code_t *)NULL; };
/**
* Close DIRECT automatically. * In reality, get back to pointer "vif_code_opened_at" and * fix immediate value with qwords counted from last packet2_vif_open_direct(). * @param packet2 Pointer to packet. */ static inline void packet2_vif_close_direct_auto(packet2_t *packet2){ return packet2_vif_close_direct_manual(packet2, ((uint32_t)packet2->next - ((uint32_t)packet2->vif_code_opened_at + 4)) >> 4); };
/**
* Add NOP VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_nop(packet2_t *packet2, uint8_t irq){ packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_NOP, irq)); };
/**
* Fill with NOP VIF opcode to align to 96bits * @param packet2 Pointer to packet. */ static inline void packet2_vif_pad96(packet2_t *packet2){ packet2_pad96(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_NOP, 0)); };
/**
* Fill with NOP VIF opcode to align to 128bits * @param packet2 Pointer to packet. */ static inline void packet2_vif_pad128(packet2_t *packet2){ packet2_pad128(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_NOP, 0)); };
/**
* Add MPG VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param num Number of 64-bit data. * @param addr Address. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_mpg(packet2_t *packet2, uint32_t num, uint32_t addr, uint8_t irq ){ packet2_add_u32(packet2, MAKE_VIF_CODE(addr, num, P2_VIF_MPG, irq)); };
/**
* Add STCYCL VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param wl WL field. * @param cl CL field. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_stcycl(packet2_t *packet2, uint32_t wl, uint32_t cl, uint8_t irq){ packet2_add_u32(packet2, MAKE_VIF_CODE(cl | (wl << 8), 0, P2_VIF_STCYCL, irq)); };
/**
* Add OFFSET VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param offset Offset. BASE+OFFSET will be the address of second buffer. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_offset( packet2_t *packet2, uint32_t offset, uint8_t irq ){ packet2_add_u32(packet2, MAKE_VIF_CODE(offset, 0, P2_VIF_OFFSET, irq)); };
/**
* Add BASE VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param base Base address of double buffer. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_base( packet2_t *packet2, uint32_t base, uint8_t irq ){ packet2_add_u32(packet2, MAKE_VIF_CODE(base, 0, P2_VIF_BASE, irq)); };
/**
* Add FLUSH VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_flush( packet2_t *packet2, uint8_t irq ){ packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_FLUSH, irq)); };
/**
* Add MSCAL VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param addr Starting address. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_mscal( packet2_t *packet2, uint32_t addr, uint8_t irq ){ packet2_add_u32(packet2, MAKE_VIF_CODE(addr, 0, P2_VIF_MSCAL, irq)); };
/**
* Add MSCNT VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_mscnt( packet2_t *packet2, uint8_t irq ){ packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_MSCNT, irq)); };
/**
* Add ITOP VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param itops Value for VU XITOP instruction. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_itop(packet2_t *packet2, uint32_t itops, uint8_t irq){ packet2_add_u32(packet2, MAKE_VIF_CODE(itops, 0, P2_VIF_ITOP, irq)); };
/**
* Add MSKPATH3 VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param mode Decompression mode. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_stmod(packet2_t *packet2, uint32_t mode, uint8_t irq){ packet2_add_u32(packet2, MAKE_VIF_CODE(mode, 0, P2_VIF_STMOD, irq)); };
/**
* Add MSKPATH3 VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param mask Mask. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_mskpath3(packet2_t *packet2, uint32_t mask, uint8_t irq){ packet2_add_u32(packet2, MAKE_VIF_CODE(mask, 0, P2_VIF_MSKPATH3, irq)); };
/**
* Add MARK VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param value Value. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_mark(packet2_t *packet2, uint32_t value, uint8_t irq){ packet2_add_u32(packet2, MAKE_VIF_CODE(value, 0, P2_VIF_MARK, irq)); };
/**
* Add FLUSHE VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_flushe(packet2_t *packet2, uint8_t irq){ packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_FLUSHE, irq)); };
/**
* Add FLUSHA VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_flusha(packet2_t *packet2, uint8_t irq){ packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_FLUSHA, irq)); };
/**
* Add MSCALF VIF opcode. * @note Alignment alert. Size of word (1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param addr Address. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_mscalf(packet2_t *packet2, uint32_t addr, uint32_t irq){ packet2_add_u32(packet2, MAKE_VIF_CODE(addr, 0, P2_VIF_MSCALF, irq)); };
/**
* Add STMASK VIF opcode. * @note Alignment alert. Size of dword (1/2). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param mask Mask. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_stmask(packet2_t *packet2, vif_mask_t mask, uint8_t irq){ packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_STMASK, irq)); packet2_add_u32(packet2, mask.m); };
/**
* Add STROW VIF opcode. * @note Alignment alert. Size of 5 x word (1+1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param row_arr Row array. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_strow(packet2_t *packet2, const uint32_t *row_arr, uint8_t irq){ packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_STROW, irq)); packet2_add_u32(packet2, row_arr[0]); packet2_add_u32(packet2, row_arr[1]); packet2_add_u32(packet2, row_arr[2]); packet2_add_u32(packet2, row_arr[3]); };
/**
* Add STCOL VIF opcode. * @note Alignment alert. Size of 5 x word (1+1/4). * For more details, check description of VIFOpcode. * @param packet2 Pointer to packet. * @param col_arr Column array. * @param irq Interrupt Request. False by default. */ static inline void packet2_vif_stcol(packet2_t *packet2, const uint32_t *col_arr, uint8_t irq ){ packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_STCOL, irq)); packet2_add_u32(packet2, col_arr[0]); packet2_add_u32(packet2, col_arr[1]); packet2_add_u32(packet2, col_arr[2]); packet2_add_u32(packet2, col_arr[3]); };
/**
* Add VU micro program into packet2. * Packet2 MODE for micro program upload: Chain * @param dest VU destination address (divided by 16). * @param start Start address. * @param end End address. */ void packet2_vif_add_micro_program(packet2_t *packet2, uint32_t dest, uint32_t *start, uint32_t *end);
#ifdef __cplusplus
}#endif
#endif
|