61
|
1 #include <stdio.h>
|
88
|
2 #include <stdlib.h>
|
|
3 #include <malloc.h>
|
59
|
4 #include "CellDmaManager.h"
|
|
5
|
|
6 void
|
88
|
7 CellDmaManager::dma_load(void *buf, uint32 addr, uint32 size, uint32 mask)
|
59
|
8 {
|
88
|
9 //if (buf == NULL || (void*)addr == NULL) return;
|
|
10 if (size == 0) return ;
|
59
|
11 spu_mfcdma32(buf, addr, ROUND_UP_ALIGN(size, DEFAULT_ALIGNMENT),
|
|
12 mask, MFC_GET_CMD);
|
|
13 }
|
|
14
|
|
15 void
|
88
|
16 CellDmaManager::dma_store(void *buf, uint32 addr, uint32 size, uint32 mask)
|
59
|
17 {
|
88
|
18 //if (buf == NULL || (void*)addr == NULL) return;
|
|
19 if (size == 0) return ;
|
59
|
20 spu_mfcdma32(buf, addr, ROUND_UP_ALIGN(size, DEFAULT_ALIGNMENT),
|
|
21 mask, MFC_PUT_CMD);
|
|
22 }
|
|
23
|
|
24 /**
|
|
25 * mask で設定した DMA 転送の完了を待つ
|
|
26 */
|
|
27 void
|
88
|
28 CellDmaManager::dma_wait(uint32 mask)
|
59
|
29 {
|
|
30 spu_writech(MFC_WrTagMask, 1 << mask);
|
|
31 spu_mfcstat(MFC_TAG_UPDATE_ALL);
|
|
32 }
|
|
33
|
|
34 void
|
88
|
35 CellDmaManager::mail_write(uint32 data)
|
59
|
36 {
|
|
37 spu_writech(SPU_WrOutMbox, data);
|
|
38 }
|
|
39
|
|
40 unsigned int
|
|
41 CellDmaManager::mail_read(void)
|
|
42 {
|
|
43 return spu_readch(SPU_RdInMbox);
|
|
44 }
|
88
|
45
|
|
46 void
|
|
47 CellDmaManager::dmaList_set(uint32 _address, uint32 _size)
|
|
48 {
|
|
49 int *index = &buff_index[buff_flag];
|
|
50 DmaListPtr queue = &dmaQueue[buff_flag][(*index)++];
|
|
51
|
|
52 queue->addr = _address;
|
|
53 queue->size = ROUND_UP_ALIGN(_size, DEFAULT_ALIGNMENT);
|
|
54 }
|
|
55
|
|
56 void**
|
|
57 CellDmaManager::dmaList_load(uint32 mask)
|
|
58 {
|
|
59 int index = buff_index[buff_flag];
|
|
60 DmaListPtr queue = dmaQueue[buff_flag];
|
|
61 mfc_list_element_t *mfc_list = mfcList[buff_flag];
|
|
62
|
|
63 void **buffList;
|
|
64 void *buff;
|
|
65 int bound;
|
|
66 int total_size = 0;
|
|
67
|
|
68 mfc_list = (mfc_list_element_t *)malloc(sizeof(mfc_list_element_t)*index);
|
|
69
|
|
70 for (int i = 0; i < index; i++) {
|
|
71 mfc_list[i].notify = 0;
|
|
72 mfc_list[i].reserved = 0;
|
|
73 mfc_list[i].size = queue[i].size;
|
|
74 mfc_list[i].eal = queue[i].addr;
|
|
75 total_size += queue[i].size;
|
|
76 }
|
|
77
|
|
78 //----------------------------------------------------------------
|
|
79 // list element が n 個ある場合の buff, buffList の構造
|
|
80 //
|
|
81 // +---------------+---------------+--------+-----------------+
|
|
82 // buff | queue[0].size | queue[1].size | ...... | queue[n-1].size |
|
|
83 // +---------------+---------------+--------+-----------------+
|
|
84 // ^ ^ ^ ^
|
|
85 // | | | |
|
|
86 // buffList[0] buffList[1] buffList[2] buffList[n-1]
|
|
87 //----------------------------------------------------------------
|
|
88
|
|
89 buff = memalign(DEFAULT_ALIGNMENT, total_size);
|
|
90 buffList = (void**)malloc(index);
|
|
91
|
|
92 bound = (int)buff;
|
|
93 buffList[0] = (void*)bound;
|
|
94 for (int i = 1; i < index; i++) {
|
|
95 bound += queue[i-1].size;
|
|
96 buffList[i] = (void*)bound;
|
|
97 }
|
|
98
|
|
99 mfc_getl(buff, 0, mfc_list, sizeof(mfc_list_element_t), mask, 0, 0);
|
|
100 dma_wait(mask);
|
|
101
|
|
102 _buffList[buff_flag] = buffList;
|
|
103 _buff[buff_flag] = buff;
|
|
104
|
|
105 return buffList;
|
|
106 }
|