1 | |
---|
2 | #ifndef FAKE_DMA_H |
---|
3 | #define FAKE_DMA_H |
---|
4 | |
---|
5 | |
---|
6 | #include "PlatformDefinitions.h" |
---|
7 | #include "LinearMath/btScalar.h" |
---|
8 | |
---|
9 | |
---|
10 | #ifdef __SPU__ |
---|
11 | |
---|
12 | #ifndef USE_LIBSPE2 |
---|
13 | |
---|
14 | #include <cell/dma.h> |
---|
15 | #include <stdint.h> |
---|
16 | |
---|
17 | #define DMA_TAG(xfer) (xfer + 1) |
---|
18 | #define DMA_MASK(xfer) (1 << DMA_TAG(xfer)) |
---|
19 | |
---|
20 | #else // !USE_LIBSPE2 |
---|
21 | |
---|
22 | #define DMA_TAG(xfer) (xfer + 1) |
---|
23 | #define DMA_MASK(xfer) (1 << DMA_TAG(xfer)) |
---|
24 | |
---|
25 | #include <spu_mfcio.h> |
---|
26 | |
---|
27 | #define DEBUG_DMA |
---|
28 | #ifdef DEBUG_DMA |
---|
29 | #define dUASSERT(a,b) if (!(a)) { printf(b);} |
---|
30 | #define uintsize ppu_address_t |
---|
31 | |
---|
32 | #define cellDmaLargeGet(ls, ea, size, tag, tid, rid) if ( (((uintsize)ls%16) != ((uintsize)ea%16)) || ((((uintsize)ea%16) || ((uintsize)ls%16)) && (( ((uintsize)ls%16) != ((uintsize)size%16) ) || ( ((uintsize)ea%16) != ((uintsize)size%16) ) ) ) || ( ((uintsize)size%16) && ((uintsize)size!=1) && ((uintsize)size!=2) && ((uintsize)size!=4) && ((uintsize)size!=8) ) || (size >= 16384) || !(uintsize)ls || !(uintsize)ea) { \ |
---|
33 | dUASSERT( (((uintsize)ea % 16) == 0) || (size < 16), "XDR Address not aligned: "); \ |
---|
34 | dUASSERT( (((uintsize)ls % 16) == 0) || (size < 16), "LS Address not aligned: "); \ |
---|
35 | dUASSERT( ((((uintsize)ls % size) == 0) && (((uintsize)ea % size) == 0)) || (size > 16), "Not naturally aligned: "); \ |
---|
36 | dUASSERT((size == 1) || (size == 2) || (size == 4) || (size == 8) || ((size % 16) == 0), "size not a multiple of 16byte: "); \ |
---|
37 | dUASSERT(size < 16384, "size too big: "); \ |
---|
38 | dUASSERT( ((uintsize)ea%16)==((uintsize)ls%16), "wrong Quadword alignment of LS and EA: "); \ |
---|
39 | dUASSERT(ea != 0, "Nullpointer EA: "); dUASSERT(ls != 0, "Nullpointer LS: ");\ |
---|
40 | printf("GET %s:%d from: 0x%x, to: 0x%x - %d bytes\n", __FILE__, __LINE__, (unsigned int)ea,(unsigned int)ls,(unsigned int)size);\ |
---|
41 | } \ |
---|
42 | mfc_get(ls, ea, size, tag, tid, rid) |
---|
43 | #define cellDmaGet(ls, ea, size, tag, tid, rid) if ( (((uintsize)ls%16) != ((uintsize)ea%16)) || ((((uintsize)ea%16) || ((uintsize)ls%16)) && (( ((uintsize)ls%16) != ((uintsize)size%16) ) || ( ((uintsize)ea%16) != ((uintsize)size%16) ) ) ) || ( ((uintsize)size%16) && ((uintsize)size!=1) && ((uintsize)size!=2) && ((uintsize)size!=4) && ((uintsize)size!=8) ) || (size >= 16384) || !(uintsize)ls || !(uintsize)ea) { \ |
---|
44 | dUASSERT( (((uintsize)ea % 16) == 0) || (size < 16), "XDR Address not aligned: "); \ |
---|
45 | dUASSERT( (((uintsize)ls % 16) == 0) || (size < 16), "LS Address not aligned: "); \ |
---|
46 | dUASSERT( ((((uintsize)ls % size) == 0) && (((uintsize)ea % size) == 0)) || (size > 16), "Not naturally aligned: "); \ |
---|
47 | dUASSERT((size == 1) || (size == 2) || (size == 4) || (size == 8) || ((size % 16) == 0), "size not a multiple of 16byte: "); \ |
---|
48 | dUASSERT(size < 16384, "size too big: "); \ |
---|
49 | dUASSERT( ((uintsize)ea%16)==((uintsize)ls%16), "wrong Quadword alignment of LS and EA: "); \ |
---|
50 | dUASSERT(ea != 0, "Nullpointer EA: "); dUASSERT(ls != 0, "Nullpointer LS: ");\ |
---|
51 | printf("GET %s:%d from: 0x%x, to: 0x%x - %d bytes\n", __FILE__, __LINE__, (unsigned int)ea,(unsigned int)ls,(unsigned int)size);\ |
---|
52 | } \ |
---|
53 | mfc_get(ls, ea, size, tag, tid, rid) |
---|
54 | #define cellDmaLargePut(ls, ea, size, tag, tid, rid) if ( (((uintsize)ls%16) != ((uintsize)ea%16)) || ((((uintsize)ea%16) || ((uintsize)ls%16)) && (( ((uintsize)ls%16) != ((uintsize)size%16) ) || ( ((uintsize)ea%16) != ((uintsize)size%16) ) ) ) || ( ((uintsize)size%16) && ((uintsize)size!=1) && ((uintsize)size!=2) && ((uintsize)size!=4) && ((uintsize)size!=8) ) || (size >= 16384) || !(uintsize)ls || !(uintsize)ea) { \ |
---|
55 | dUASSERT( (((uintsize)ea % 16) == 0) || (size < 16), "XDR Address not aligned: "); \ |
---|
56 | dUASSERT( (((uintsize)ls % 16) == 0) || (size < 16), "LS Address not aligned: "); \ |
---|
57 | dUASSERT( ((((uintsize)ls % size) == 0) && (((uintsize)ea % size) == 0)) || (size > 16), "Not naturally aligned: "); \ |
---|
58 | dUASSERT((size == 1) || (size == 2) || (size == 4) || (size == 8) || ((size % 16) == 0), "size not a multiple of 16byte: "); \ |
---|
59 | dUASSERT(size < 16384, "size too big: "); \ |
---|
60 | dUASSERT( ((uintsize)ea%16)==((uintsize)ls%16), "wrong Quadword alignment of LS and EA: "); \ |
---|
61 | dUASSERT(ea != 0, "Nullpointer EA: "); dUASSERT(ls != 0, "Nullpointer LS: ");\ |
---|
62 | printf("PUT %s:%d from: 0x%x, to: 0x%x - %d bytes\n", __FILE__, __LINE__, (unsigned int)ls,(unsigned int)ea,(unsigned int)size); \ |
---|
63 | } \ |
---|
64 | mfc_put(ls, ea, size, tag, tid, rid) |
---|
65 | #define cellDmaSmallGet(ls, ea, size, tag, tid, rid) if ( (((uintsize)ls%16) != ((uintsize)ea%16)) || ((((uintsize)ea%16) || ((uintsize)ls%16)) && (( ((uintsize)ls%16) != ((uintsize)size%16) ) || ( ((uintsize)ea%16) != ((uintsize)size%16) ) ) ) || ( ((uintsize)size%16) && ((uintsize)size!=1) && ((uintsize)size!=2) && ((uintsize)size!=4) && ((uintsize)size!=8) ) || (size >= 16384) || !(uintsize)ls || !(uintsize)ea) { \ |
---|
66 | dUASSERT( (((uintsize)ea % 16) == 0) || (size < 16), "XDR Address not aligned: "); \ |
---|
67 | dUASSERT( (((uintsize)ls % 16) == 0) || (size < 16), "LS Address not aligned: "); \ |
---|
68 | dUASSERT( ((((uintsize)ls % size) == 0) && (((uintsize)ea % size) == 0)) || (size > 16), "Not naturally aligned: "); \ |
---|
69 | dUASSERT((size == 1) || (size == 2) || (size == 4) || (size == 8) || ((size % 16) == 0), "size not a multiple of 16byte: "); \ |
---|
70 | dUASSERT(size < 16384, "size too big: "); \ |
---|
71 | dUASSERT( ((uintsize)ea%16)==((uintsize)ls%16), "wrong Quadword alignment of LS and EA: "); \ |
---|
72 | dUASSERT(ea != 0, "Nullpointer EA: "); dUASSERT(ls != 0, "Nullpointer LS: ");\ |
---|
73 | printf("GET %s:%d from: 0x%x, to: 0x%x - %d bytes\n", __FILE__, __LINE__, (unsigned int)ea,(unsigned int)ls,(unsigned int)size);\ |
---|
74 | } \ |
---|
75 | mfc_get(ls, ea, size, tag, tid, rid) |
---|
76 | #define cellDmaWaitTagStatusAll(ignore) mfc_write_tag_mask(ignore) ; mfc_read_tag_status_all() |
---|
77 | |
---|
78 | #else |
---|
79 | #define cellDmaLargeGet(ls, ea, size, tag, tid, rid) mfc_get(ls, ea, size, tag, tid, rid) |
---|
80 | #define cellDmaGet(ls, ea, size, tag, tid, rid) mfc_get(ls, ea, size, tag, tid, rid) |
---|
81 | #define cellDmaLargePut(ls, ea, size, tag, tid, rid) mfc_put(ls, ea, size, tag, tid, rid) |
---|
82 | #define cellDmaSmallGet(ls, ea, size, tag, tid, rid) mfc_get(ls, ea, size, tag, tid, rid) |
---|
83 | #define cellDmaWaitTagStatusAll(ignore) mfc_write_tag_mask(ignore) ; mfc_read_tag_status_all() |
---|
84 | #endif // DEBUG_DMA |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | #endif // USE_LIBSPE2 |
---|
94 | #else // !__SPU__ |
---|
95 | //Simulate DMA using memcpy or direct access on non-CELL platforms that don't have DMAs and SPUs (Win32, Mac, Linux etc) |
---|
96 | //Potential to add networked simulation using this interface |
---|
97 | |
---|
98 | #define DMA_TAG(a) (a) |
---|
99 | #define DMA_MASK(a) (a) |
---|
100 | |
---|
101 | /// cellDmaLargeGet Win32 replacements for Cell DMA to allow simulating most of the SPU code (just memcpy) |
---|
102 | int cellDmaLargeGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid); |
---|
103 | int cellDmaGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid); |
---|
104 | /// cellDmaLargePut Win32 replacements for Cell DMA to allow simulating most of the SPU code (just memcpy) |
---|
105 | int cellDmaLargePut(const void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid); |
---|
106 | /// cellDmaWaitTagStatusAll Win32 replacements for Cell DMA to allow simulating most of the SPU code (just memcpy) |
---|
107 | void cellDmaWaitTagStatusAll(int ignore); |
---|
108 | |
---|
109 | |
---|
110 | #endif //__CELLOS_LV2__ |
---|
111 | |
---|
112 | ///stallingUnalignedDmaSmallGet internally uses DMA_TAG(1) |
---|
113 | int stallingUnalignedDmaSmallGet(void *ls, uint64_t ea, uint32_t size); |
---|
114 | |
---|
115 | |
---|
116 | void* cellDmaLargeGetReadOnly(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid); |
---|
117 | void* cellDmaGetReadOnly(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid); |
---|
118 | void* cellDmaSmallGetReadOnly(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid); |
---|
119 | |
---|
120 | |
---|
121 | #endif //FAKE_DMA_H |
---|