-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmctools_rpc.c
executable file
·217 lines (163 loc) · 7.75 KB
/
mctools_rpc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include <errno.h>
#include <iopheap.h>
#include <kernel.h>
#include <sifrpc.h>
#include <string.h>
#include "mctools_rpc.h"
static SifRpcClientData_t MCTOOLS_rpc_cd;
static struct MCTools_AlignmentData MCTools_BufferAlignmentData ALIGNED(16);
static void *IopBuffer;
static unsigned int IopBufferSize;
static unsigned char TransmitBuffer[1024] ALIGNED(64);
static unsigned char ReceiveBuffer[64] ALIGNED(64);
static void MCTOOLS_RpcEndFunc(void *AlignmentData){
memcpy(((struct MCTools_AlignmentData *)UNCACHED_SEG(AlignmentData))->buffer1Address, ((struct MCTools_AlignmentData *)UNCACHED_SEG(AlignmentData))->buffer1, ((struct MCTools_AlignmentData *)UNCACHED_SEG(AlignmentData))->buffer1_len);
memcpy(((struct MCTools_AlignmentData *)UNCACHED_SEG(AlignmentData))->buffer2Address, ((struct MCTools_AlignmentData *)UNCACHED_SEG(AlignmentData))->buffer2, ((struct MCTools_AlignmentData *)UNCACHED_SEG(AlignmentData))->buffer2_len);
}
void InitMCTOOLS(void){
void *data;
while((SifBindRpc(&MCTOOLS_rpc_cd, MCTOOLS_RPC_NUM, 0)<0) || (MCTOOLS_rpc_cd.server == NULL)) nopdelay();
IopBufferSize=8192;
IopBuffer=SifAllocIopHeap(IopBufferSize);
data=&MCTools_BufferAlignmentData;
SifCallRpc(&MCTOOLS_rpc_cd, MCTOOLS_Init, 0, &data, sizeof(void *), NULL, 0, NULL, NULL);
}
void DeinitMCTOOLS(void){
memset(&MCTOOLS_rpc_cd, 0, sizeof(SifRpcClientData_t));
if(IopBuffer!=NULL) SifFreeIopHeap(IopBuffer);
}
static int CheckIOPBufferSize(int size){
int result;
if(size>IopBufferSize){
if(IopBuffer!=NULL) SifFreeIopHeap(IopBuffer);
if((IopBuffer=SifAllocIopHeap(size))!=NULL){
result=size;
IopBufferSize=size;
} else {
result=-ENOMEM;
IopBufferSize=0;
}
} else
result=0;
return result;
}
int MCToolsCreateCrossLinkedFiles(int port, int slot, const char *path, struct FileAlias *NewAliases, int count){
struct MCTools_CrossLinkedEntRPCData *TargetData;
int RPC_res;
unsigned int i;
TargetData=(struct MCTools_CrossLinkedEntRPCData *)TransmitBuffer;
TargetData->port=port;
TargetData->slot=slot;
strncpy(TargetData->path, path, sizeof(TargetData->path));
for(i=0; (i<MAX_RPC_FILE_ENTRIES) && (i<count); i++) memcpy(&TargetData->Aliases[i], &NewAliases[i], sizeof(TargetData->Aliases[i]));
if(i<MAX_RPC_FILE_ENTRIES) TargetData->Aliases[i].name[0]='\0'; /* NULL terminate the last entry. */
if((RPC_res=SifCallRpc(&MCTOOLS_rpc_cd, MCTOOLS_CreateCrossLinkedEnts, 0, TargetData, sizeof(struct MCTools_CrossLinkedEntRPCData), ReceiveBuffer, sizeof(int), NULL, NULL))>=0) RPC_res=*(int *)ReceiveBuffer;
return RPC_res;
}
int MCToolsDeleteCrossLinkedFiles(int port, int slot, const char *path, struct FileAlias *Aliases, int count){
struct MCTools_CrossLinkedEntRPCData *TargetData;
int RPC_res;
unsigned int i;
TargetData=(struct MCTools_CrossLinkedEntRPCData *)TransmitBuffer;
TargetData->port=port;
TargetData->slot=slot;
strncpy(TargetData->path, path, sizeof(TargetData->path));
for(i=0; (i<MAX_RPC_FILE_ENTRIES) && (i<count); i++) memcpy(&TargetData->Aliases[i], &Aliases[i], sizeof(TargetData->Aliases[i]));
if(i<MAX_RPC_FILE_ENTRIES) TargetData->Aliases[i].name[0]='\0'; /* NULL terminate the last entry. */
if((RPC_res=SifCallRpc(&MCTOOLS_rpc_cd, MCTOOLS_DeleteCrossLinkedEnts, 0, TargetData, sizeof(struct MCTools_CrossLinkedEntRPCData), ReceiveBuffer, sizeof(int), NULL, NULL))>=0) RPC_res=*(int *)ReceiveBuffer;
return RPC_res;
}
int MCToolsGetMCInfo(int port, int slot, struct MCTools_McSpecData *McSpecData){
struct MCTools_GetMCInfoRPCReqData *MCInfoRPCData;
int RPC_res;
MCInfoRPCData=(struct MCTools_GetMCInfoRPCReqData *)TransmitBuffer;
MCInfoRPCData->SpecData=McSpecData;
MCInfoRPCData->port=port;
MCInfoRPCData->slot=slot;
if((RPC_res=SifCallRpc(&MCTOOLS_rpc_cd, MCTOOLS_GetMCInfo, 0, MCInfoRPCData, sizeof(struct MCTools_GetMCInfoRPCReqData), ReceiveBuffer, sizeof(struct MCTools_GetMCInfoRPCResData), &MCTOOLS_RpcEndFunc, &MCTools_BufferAlignmentData))>=0){
RPC_res=((struct MCTools_GetMCInfoRPCResData*)ReceiveBuffer)->result;
memcpy(McSpecData, &((struct MCTools_GetMCInfoRPCResData*)ReceiveBuffer)->SpecData, sizeof(struct MCTools_McSpecData));
}
return RPC_res;
}
int MCToolsInitPageCache(int port, int slot){
struct MCTools_CacheRPCData *CacheRPCData;
int RPC_res;
CacheRPCData=(struct MCTools_CacheRPCData *)TransmitBuffer;
CacheRPCData->port=port;
CacheRPCData->slot=slot;
if((RPC_res=SifCallRpc(&MCTOOLS_rpc_cd, MCTOOLS_InitPageCache, 0, CacheRPCData, sizeof(struct MCTools_CacheRPCData), ReceiveBuffer, sizeof(int), NULL, NULL))>=0) RPC_res=*(int *)ReceiveBuffer;
return RPC_res;
}
int MCToolsFlushPageCache(void){
int RPC_res;
if((RPC_res=SifCallRpc(&MCTOOLS_rpc_cd, MCTOOLS_FlushPageCache, 0, NULL, 0, ReceiveBuffer, sizeof(int), NULL, NULL))>=0) RPC_res=*(int *)ReceiveBuffer;
return RPC_res;
}
/*
* Functions starting from here onwards are asynchronous or are helper functions for asynchronous functions.
*/
int MCToolsAsyncGetLastError(void){
return *(int *)ReceiveBuffer;
}
int MCToolsReadCluster(int port, int slot, unsigned int cluster, unsigned short int ClusterSize, const struct MCTools_McSpecData *McSpecData, void *buffer){
int result;
struct MCTools_ReadWriteRPCData *ReadClusterRPCData;
if(CheckIOPBufferSize(McSpecData->PageSize*ClusterSize)>=0){
ReadClusterRPCData=(struct MCTools_ReadWriteRPCData *)TransmitBuffer;
ReadClusterRPCData->port=port;
ReadClusterRPCData->slot=slot;
ReadClusterRPCData->offset=cluster;
ReadClusterRPCData->PageSize=McSpecData->PageSize;
ReadClusterRPCData->BlockSize=ClusterSize;
ReadClusterRPCData->EEbuffer=buffer;
ReadClusterRPCData->IOPbuffer=IopBuffer;
SifWriteBackDCache(buffer, McSpecData->PageSize*ClusterSize);
result=SifCallRpc(&MCTOOLS_rpc_cd, MCTOOLS_ReadCluster, SIF_RPC_M_NOWAIT, ReadClusterRPCData, sizeof(struct MCTools_ReadWriteRPCData), ReceiveBuffer, sizeof(int), &MCTOOLS_RpcEndFunc, &MCTools_BufferAlignmentData);
}
else result=-ENOMEM;
return result;
}
int MCToolsWriteBlock(int port, int slot, unsigned int block, const struct MCTools_McSpecData *McSpecData, void *buffer){
struct MCTools_ReadWriteRPCData *WriteBlockRPCData;
int DMATransferID, BlockSize, result;
SifDmaTransfer_t dmat;
BlockSize=McSpecData->PageSize*McSpecData->BlockSize;
if(CheckIOPBufferSize(BlockSize)>=0){
WriteBlockRPCData=(struct MCTools_ReadWriteRPCData *)TransmitBuffer;
dmat.src=buffer;
dmat.dest=IopBuffer;
dmat.size=BlockSize;
dmat.attr=0;
SifWriteBackDCache(buffer, BlockSize);
while((DMATransferID=SifSetDma(&dmat, 1))==0){};
WriteBlockRPCData->port=port;
WriteBlockRPCData->slot=slot;
WriteBlockRPCData->offset=block;
WriteBlockRPCData->PageSize=McSpecData->PageSize;
WriteBlockRPCData->BlockSize=McSpecData->BlockSize;
WriteBlockRPCData->IOPbuffer=dmat.dest;
while(SifDmaStat(DMATransferID)>=0){};
result=SifCallRpc(&MCTOOLS_rpc_cd, MCTOOLS_WriteBlock, SIF_RPC_M_NOWAIT, WriteBlockRPCData, sizeof(struct MCTools_ReadWriteRPCData), ReceiveBuffer, sizeof(int), NULL, NULL);
}
else result=-ENOMEM;
return result;
}
int MCToolsSync(int mode){
int result;
switch(mode){
case 1:
result=SifCheckStatRpc(&MCTOOLS_rpc_cd);
break;
default:
while(SifCheckStatRpc(&MCTOOLS_rpc_cd)!=0){};
result=0;
}
return result;
}
int MCToolsFlushMCMANClusterCache(int port, int slot){
int result;
((struct MCTools_MCMANFlushCommandData*)TransmitBuffer)->port=port;
((struct MCTools_MCMANFlushCommandData*)TransmitBuffer)->slot=slot;
return(((result=SifCallRpc(&MCTOOLS_rpc_cd, MCTOOLS_FlushMCMANClusterCache, 0, TransmitBuffer, sizeof(struct MCTools_MCMANFlushCommandData), ReceiveBuffer, sizeof(int), NULL, NULL))>=0)?*(int*)ReceiveBuffer:result);
}