[1966] | 1 | |
---|
| 2 | #include "SpuFakeDma.h" |
---|
| 3 | #include <LinearMath/btScalar.h> //for btAssert |
---|
| 4 | //Disabling memcpy sometimes helps debugging DMA |
---|
| 5 | |
---|
| 6 | #define USE_MEMCPY 1 |
---|
| 7 | #ifdef USE_MEMCPY |
---|
| 8 | |
---|
| 9 | #endif |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | void* cellDmaLargeGetReadOnly(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid) |
---|
| 13 | { |
---|
| 14 | |
---|
| 15 | #if defined (__CELLOS_LV2__) || defined (USE_LIBSPE2) |
---|
| 16 | cellDmaLargeGet(ls,ea,size,tag,tid,rid); |
---|
| 17 | return ls; |
---|
| 18 | #else |
---|
| 19 | return (void*)(uint32_t)ea; |
---|
| 20 | #endif |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | void* cellDmaSmallGetReadOnly(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid) |
---|
| 24 | { |
---|
| 25 | #if defined (__SPU__) || defined (USE_LIBSPE2) |
---|
| 26 | mfc_get(ls,ea,size,tag,0,0); |
---|
| 27 | return ls; |
---|
| 28 | #else |
---|
| 29 | return (void*)(uint32_t)ea; |
---|
| 30 | #endif |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | void* cellDmaGetReadOnly(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid) |
---|
| 37 | { |
---|
| 38 | #if defined (__SPU__) || defined (USE_LIBSPE2) |
---|
| 39 | cellDmaGet(ls,ea,size,tag,tid,rid); |
---|
| 40 | return ls; |
---|
| 41 | #else |
---|
| 42 | return (void*)(uint32_t)ea; |
---|
| 43 | #endif |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | ///this unalignedDma should not be frequently used, only for small data. It handles alignment and performs check on size (<16 bytes) |
---|
| 48 | int stallingUnalignedDmaSmallGet(void *ls, uint64_t ea, uint32_t size) |
---|
| 49 | { |
---|
| 50 | |
---|
| 51 | btAssert(size<32); |
---|
| 52 | |
---|
| 53 | ATTRIBUTE_ALIGNED16(char tmpBuffer[32]); |
---|
| 54 | |
---|
| 55 | char* mainMem = (char*)ea; |
---|
| 56 | char* localStore = (char*)ls; |
---|
| 57 | uint32_t i; |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | ///make sure last 4 bits are the same, for cellDmaSmallGet |
---|
| 61 | uint32_t last4BitsOffset = ea & 0x0f; |
---|
| 62 | char* tmpTarget = tmpBuffer + last4BitsOffset; |
---|
| 63 | |
---|
| 64 | #if defined (__SPU__) || defined (USE_LIBSPE2) |
---|
| 65 | |
---|
| 66 | int remainingSize = size; |
---|
| 67 | |
---|
| 68 | //#define FORCE_cellDmaUnalignedGet 1 |
---|
| 69 | #ifdef FORCE_cellDmaUnalignedGet |
---|
| 70 | cellDmaUnalignedGet(tmpTarget,ea,size,DMA_TAG(1),0,0); |
---|
| 71 | #else |
---|
| 72 | char* remainingTmpTarget = tmpTarget; |
---|
| 73 | uint64_t remainingEa = ea; |
---|
| 74 | |
---|
| 75 | while (remainingSize) |
---|
| 76 | { |
---|
| 77 | switch (remainingSize) |
---|
| 78 | { |
---|
| 79 | case 1: |
---|
| 80 | case 2: |
---|
| 81 | case 4: |
---|
| 82 | case 8: |
---|
| 83 | case 16: |
---|
| 84 | { |
---|
| 85 | mfc_get(remainingTmpTarget,remainingEa,remainingSize,DMA_TAG(1),0,0); |
---|
| 86 | remainingSize=0; |
---|
| 87 | break; |
---|
| 88 | } |
---|
| 89 | default: |
---|
| 90 | { |
---|
| 91 | //spu_printf("unaligned DMA with non-natural size:%d\n",remainingSize); |
---|
| 92 | int actualSize = 0; |
---|
| 93 | |
---|
| 94 | if (remainingSize > 16) |
---|
| 95 | actualSize = 16; |
---|
| 96 | else |
---|
| 97 | if (remainingSize >8) |
---|
| 98 | actualSize=8; |
---|
| 99 | else |
---|
| 100 | if (remainingSize >4) |
---|
| 101 | actualSize=4; |
---|
| 102 | else |
---|
| 103 | if (remainingSize >2) |
---|
| 104 | actualSize=2; |
---|
| 105 | mfc_get(remainingTmpTarget,remainingEa,actualSize,DMA_TAG(1),0,0); |
---|
| 106 | remainingSize-=actualSize; |
---|
| 107 | remainingTmpTarget+=actualSize; |
---|
| 108 | remainingEa += actualSize; |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | #endif//FORCE_cellDmaUnalignedGet |
---|
| 113 | |
---|
| 114 | #else |
---|
| 115 | //copy into final destination |
---|
| 116 | #ifdef USE_MEMCPY |
---|
| 117 | memcpy(tmpTarget,mainMem,size); |
---|
| 118 | #else |
---|
| 119 | for ( i=0;i<size;i++) |
---|
| 120 | { |
---|
| 121 | tmpTarget[i] = mainMem[i]; |
---|
| 122 | } |
---|
| 123 | #endif //USE_MEMCPY |
---|
| 124 | |
---|
| 125 | #endif |
---|
| 126 | |
---|
| 127 | cellDmaWaitTagStatusAll(DMA_MASK(1)); |
---|
| 128 | |
---|
| 129 | //this is slowish, perhaps memcpy on SPU is smarter? |
---|
| 130 | for (i=0; btLikely( i<size );i++) |
---|
| 131 | { |
---|
| 132 | localStore[i] = tmpTarget[i]; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | return 0; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | #if defined (__SPU__) || defined (USE_LIBSPE2) |
---|
| 139 | #else |
---|
| 140 | |
---|
| 141 | int cellDmaLargeGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid) |
---|
| 142 | { |
---|
| 143 | char* mainMem = (char*)ea; |
---|
| 144 | char* localStore = (char*)ls; |
---|
| 145 | |
---|
| 146 | #ifdef USE_MEMCPY |
---|
| 147 | memcpy(localStore,mainMem,size); |
---|
| 148 | #else |
---|
| 149 | for (uint32_t i=0;i<size;i++) |
---|
| 150 | { |
---|
| 151 | localStore[i] = mainMem[i]; |
---|
| 152 | } |
---|
| 153 | #endif |
---|
| 154 | return 0; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | int cellDmaGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid) |
---|
| 158 | { |
---|
| 159 | char* mainMem = (char*)ea; |
---|
| 160 | char* localStore = (char*)ls; |
---|
| 161 | #ifdef USE_MEMCPY |
---|
| 162 | memcpy(localStore,mainMem,size); |
---|
| 163 | #else |
---|
| 164 | for (uint32_t i=0;i<size;i++) |
---|
| 165 | { |
---|
| 166 | localStore[i] = mainMem[i]; |
---|
| 167 | } |
---|
| 168 | #endif //#ifdef USE_MEMCPY |
---|
| 169 | return 0; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | int cellDmaLargePut(const void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid) |
---|
| 173 | { |
---|
| 174 | char* mainMem = (char*)ea; |
---|
| 175 | const char* localStore = (const char*)ls; |
---|
| 176 | #ifdef USE_MEMCPY |
---|
| 177 | memcpy(mainMem,localStore,size); |
---|
| 178 | #else |
---|
| 179 | for (uint32_t i=0;i<size;i++) |
---|
| 180 | { |
---|
| 181 | mainMem[i] = localStore[i]; |
---|
| 182 | } |
---|
| 183 | #endif //#ifdef USE_MEMCPY |
---|
| 184 | |
---|
| 185 | return 0; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | void cellDmaWaitTagStatusAll(int ignore) |
---|
| 191 | { |
---|
| 192 | |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | #endif |
---|