25#define RPC_PACKET_SIZE 64
28#define PACKET_F_ALLOC 0x01
30static inline void rpc_packet_free(
void *packet)
35 rendpkt->rec_id &= (~PACKET_F_ALLOC);
53extern int _iop_reboot_count;
59#ifdef F__rpc_get_packet
72 for (rid = 0; rid < len; rid++, packet = (
SifRpcPktHeader_t *)(((
unsigned char *)packet) + RPC_PACKET_SIZE)) {
91 packet->pkt_addr = packet;
100#ifdef F__rpc_get_fpacket
106 rpc_data->rdata_table_idx = index + 1;
108 return (
void *)(
rpc_data->rdata_table + (index * RPC_PACKET_SIZE));
124 cd->hdr.pkt_addr = bind;
125 cd->hdr.rpc_id = bind->rpc_id;
126 cd->hdr.sema_id = -1;
129 bind->pkt_addr = bind;
133 if (!SifSendCmd(SIF_CMD_RPC_BIND, bind, RPC_PACKET_SIZE, NULL, NULL, 0)) {
134 rpc_packet_free(bind);
143 cd->hdr.sema_id = CreateSema(&sema);
144 if (cd->hdr.sema_id < 0) {
145 rpc_packet_free(bind);
149 if (!SifSendCmd(SIF_CMD_RPC_BIND, bind, RPC_PACKET_SIZE, NULL, NULL, 0)) {
150 rpc_packet_free(bind);
151 DeleteSema(cd->hdr.sema_id);
155 WaitSema(cd->hdr.sema_id);
156 DeleteSema(cd->hdr.sema_id);
164 void *sendbuf,
int ssize,
void *recvbuf,
int rsize,
165 SifRpcEndFunc_t endfunc,
void *efarg)
174 cd->hdr.pkt_addr = call;
175 cd->hdr.rpc_id = call->rpc_id;
176 cd->hdr.sema_id = -1;
177 cd->end_function = endfunc;
178 cd->end_param = efarg;
180 call->rpc_number = rpc_number;
181 call->send_size = ssize;
182 call->receive = recvbuf;
183 call->recv_size = rsize;
185 call->pkt_addr = call;
187 call->server = cd->server;
191 SifWriteBackDCache(sendbuf, ssize);
193 SifWriteBackDCache(recvbuf, rsize);
200 if (!SifSendCmd(SIF_CMD_RPC_CALL, call, RPC_PACKET_SIZE, sendbuf, cd->buff, ssize)) {
201 rpc_packet_free(call);
210 cd->hdr.sema_id = CreateSema(&sema);
211 if (cd->hdr.sema_id < 0) {
212 rpc_packet_free(call);
216 if (!SifSendCmd(SIF_CMD_RPC_CALL, call, RPC_PACKET_SIZE, sendbuf, cd->buff, ssize)) {
217 rpc_packet_free(call);
218 DeleteSema(cd->hdr.sema_id);
222 WaitSema(cd->hdr.sema_id);
223 DeleteSema(cd->hdr.sema_id);
229#ifdef F_SifRpcGetOtherData
240 rd->hdr.pkt_addr = other;
241 rd->hdr.rpc_id = other->rpc_id;
242 rd->hdr.sema_id = -1;
250 if (!SifSendCmd(SIF_CMD_RPC_RDATA, other, RPC_PACKET_SIZE, NULL, NULL, 0)) {
251 rpc_packet_free(other);
260 rd->hdr.sema_id = CreateSema(&sema);
261 if (rd->hdr.sema_id < 0) {
262 rpc_packet_free(other);
266 if (!SifSendCmd(SIF_CMD_RPC_RDATA, other, RPC_PACKET_SIZE, NULL, NULL, 0)) {
267 rpc_packet_free(other);
268 DeleteSema(rd->hdr.sema_id);
272 WaitSema(rd->hdr.sema_id);
273 DeleteSema(rd->hdr.sema_id);
289 pkt_table : pkt_table,
290 pkt_table_len :
sizeof(pkt_table) / RPC_PACKET_SIZE,
291 rdata_table : rdata_table,
292 rdata_table_len : sizeof(rdata_table) / RPC_PACKET_SIZE,
293 client_table : client_table,
294 client_table_len : sizeof(client_table) / RPC_PACKET_SIZE,
308 if (
request->cid == SIF_CMD_RPC_CALL) {
309 if (client->end_function)
310 client->end_function(client->end_param);
311 }
else if (
request->cid == SIF_CMD_RPC_BIND) {
312 client->server =
request->server;
314 client->cbuff =
request->cbuff;
317 if (client->hdr.sema_id >= 0)
318 iSignalSema(client->hdr.sema_id);
320 rpc_packet_free(client->hdr.pkt_addr);
321 client->hdr.pkt_addr = NULL;
333 server = queue->link;
335 if ((u32)(server->sid) == sid)
338 server = server->link;
353 rend = _rpc_get_fpacket(data);
354 rend->pkt_addr = bind->pkt_addr;
355 rend->client = bind->client;
356 rend->cid = SIF_CMD_RPC_BIND;
358 server = search_svdata(bind->sid, data);
364 rend->server = server;
365 rend->buff = server->buff;
366 rend->cbuff = server->cbuff;
369 iSifSendCmd(SIF_CMD_RPC_END, rend, RPC_PACKET_SIZE, NULL, NULL, 0);
381 base->end->next = server;
383 base->start = server;
386 server->pkt_addr =
request->pkt_addr;
387 server->client =
request->client;
388 server->rpc_number =
request->rpc_number;
389 server->size =
request->send_size;
390 server->receive =
request->receive;
391 server->rsize =
request->recv_size;
392 server->rmode =
request->rmode;
395 if (base->thread_id < 0 || base->active != 0)
398 iWakeupThread(base->thread_id);
407 rend->pkt_addr = rdata->pkt_addr;
409 rend->cid = SIF_CMD_RPC_RDATA;
411 iSifSendCmd(SIF_CMD_RPC_END, rend, RPC_PACKET_SIZE, rdata->src, rdata->dest, rdata->size);
414void SifInitRpc(
int mode)
420 static int _rb_count = 0;
421 if (_rb_count != _iop_reboot_count) {
422 _rb_count = _iop_reboot_count;
434 _sif_rpc_data.pkt_table = UNCACHED_SEG(_sif_rpc_data.pkt_table);
435 _sif_rpc_data.rdata_table = UNCACHED_SEG(_sif_rpc_data.rdata_table);
436 _sif_rpc_data.client_table = UNCACHED_SEG(_sif_rpc_data.client_table);
438 _sif_rpc_data.rdata_table_idx = 0;
446 for (rid = 0; rid < len; rid++, packet = (
SifRpcPktHeader_t *)(((
unsigned char *)packet) + RPC_PACKET_SIZE)) {
447 rpc_packet_free(packet);
451 SifAddCmdHandler(SIF_CMD_RPC_END, (
void *)_request_end, &_sif_rpc_data);
452 SifAddCmdHandler(SIF_CMD_RPC_BIND, (
void *)_request_bind, &_sif_rpc_data);
453 SifAddCmdHandler(SIF_CMD_RPC_CALL, (
void *)_request_call, &_sif_rpc_data);
454 SifAddCmdHandler(SIF_CMD_RPC_RDATA, (
void *)_request_rdata, &_sif_rpc_data);
457 if (SifGetReg(SIF_SYSREG_RPCINIT))
460 cmdp = (u32 *)&pkt_table[64];
462 SifSendCmd(SIF_CMD_INIT_CMD, cmdp, 16, NULL, NULL, 0);
466 SifSetReg(SIF_SYSREG_RPCINIT, 1);
476#ifdef F_SifRegisterRpc
479 int sid, SifRpcFunc_t func,
void *buff, SifRpcFunc_t cfunc,
495 if (!(server = qd->link)) {
498 while (server->link != NULL) {
499 server = server->link;
519 if ((server = queue->link) == sd) {
520 queue->link = server->link;
522 while (server != NULL) {
523 if (server->link == sd) {
524 server->link = sd->link;
528 server = server->link;
538#ifdef F_SifSetRpcQueue
546 qd->thread_id = thread_id;
553 if (_sif_rpc_data.active_queue == NULL) {
554 _sif_rpc_data.active_queue = qd;
556 queue = _sif_rpc_data.active_queue;
558 while (queue->next != NULL)
570#ifdef F_SifRemoveRpcQueue
578 if ((queue = _sif_rpc_data.active_queue) == qd) {
579 _sif_rpc_data.active_queue = queue->next;
581 while (queue != NULL) {
582 if (queue->next == qd) {
583 queue->next = qd->next;
597#ifdef F_SifGetNextRequest
606 if (server != NULL) {
608 qd->start = server->next;
619#ifdef F_SifExecRequest
622 if (rid < 0 || rid < rpc_data->client_table_len)
625 return rpc_data->client_table + (rid * RPC_PACKET_SIZE);
634 rec = sd->func(sd->rpc_number, sd->buff, sd->size);
637 SifWriteBackDCache(sd->buff, sd->size);
640 SifWriteBackDCache(rec, sd->rsize);
646 _rpc_get_fpacket2(&_sif_rpc_data, (sd->rid >> 16) & 0xffff);
649 _rpc_get_fpacket(&_sif_rpc_data);
653 rend->client = sd->client;
654 rend->cid = SIF_CMD_RPC_CALL;
657 if (!SifSendCmd(SIF_CMD_RPC_END, rend, RPC_PACKET_SIZE, rec, sd->receive,
667 dmat.dest = sd->receive;
668 dmat.size = sd->rsize;
672 dmat.dest = sd->pkt_addr;
677 while (!SifSetDma(&dmat, 1))
688 while ((server = SifGetNextRequest(qd)))
689 SifExecRequest(server);
696#ifdef F_SifCheckStatRpc
704 if (cd->hdr.rpc_id != (u32)(packet->rpc_id))