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);
154 WaitSema(cd->hdr.sema_id);
155 DeleteSema(cd->hdr.sema_id);
163 void *sendbuf,
int ssize,
void *recvbuf,
int rsize,
164 SifRpcEndFunc_t endfunc,
void *efarg)
173 cd->hdr.pkt_addr = call;
174 cd->hdr.rpc_id = call->rpc_id;
175 cd->hdr.sema_id = -1;
176 cd->end_function = endfunc;
177 cd->end_param = efarg;
179 call->rpc_number = rpc_number;
180 call->send_size = ssize;
181 call->receive = recvbuf;
182 call->recv_size = rsize;
184 call->pkt_addr = call;
186 call->server = cd->server;
190 SifWriteBackDCache(sendbuf, ssize);
192 SifWriteBackDCache(recvbuf, rsize);
199 if (!SifSendCmd(SIF_CMD_RPC_CALL, call, RPC_PACKET_SIZE, sendbuf, cd->buff, ssize)) {
200 rpc_packet_free(call);
209 cd->hdr.sema_id = CreateSema(&sema);
210 if (cd->hdr.sema_id < 0) {
211 rpc_packet_free(call);
215 if (!SifSendCmd(SIF_CMD_RPC_CALL, call, RPC_PACKET_SIZE, sendbuf, cd->buff, ssize)) {
216 rpc_packet_free(call);
220 WaitSema(cd->hdr.sema_id);
221 DeleteSema(cd->hdr.sema_id);
227#ifdef F_SifRpcGetOtherData
238 rd->hdr.pkt_addr = other;
239 rd->hdr.rpc_id = other->rpc_id;
240 rd->hdr.sema_id = -1;
248 if (!SifSendCmd(SIF_CMD_RPC_RDATA, other, RPC_PACKET_SIZE, NULL, NULL, 0)) {
249 rpc_packet_free(other);
258 rd->hdr.sema_id = CreateSema(&sema);
259 if (rd->hdr.sema_id < 0) {
260 rpc_packet_free(other);
264 if (!SifSendCmd(SIF_CMD_RPC_RDATA, other, RPC_PACKET_SIZE, NULL, NULL, 0)) {
265 rpc_packet_free(other);
269 WaitSema(rd->hdr.sema_id);
270 DeleteSema(rd->hdr.sema_id);
286 pkt_table : pkt_table,
287 pkt_table_len :
sizeof(pkt_table) / RPC_PACKET_SIZE,
288 rdata_table : rdata_table,
289 rdata_table_len : sizeof(rdata_table) / RPC_PACKET_SIZE,
290 client_table : client_table,
291 client_table_len : sizeof(client_table) / RPC_PACKET_SIZE,
305 if (
request->cid == SIF_CMD_RPC_CALL) {
306 if (client->end_function)
307 client->end_function(client->end_param);
308 }
else if (
request->cid == SIF_CMD_RPC_BIND) {
309 client->server =
request->server;
311 client->cbuff =
request->cbuff;
314 if (client->hdr.sema_id >= 0)
315 iSignalSema(client->hdr.sema_id);
317 rpc_packet_free(client->hdr.pkt_addr);
318 client->hdr.pkt_addr = NULL;
330 server = queue->link;
332 if ((u32)(server->sid) == sid)
335 server = server->link;
350 rend = _rpc_get_fpacket(data);
351 rend->pkt_addr = bind->pkt_addr;
352 rend->client = bind->client;
353 rend->cid = SIF_CMD_RPC_BIND;
355 server = search_svdata(bind->sid, data);
361 rend->server = server;
362 rend->buff = server->buff;
363 rend->cbuff = server->cbuff;
366 iSifSendCmd(SIF_CMD_RPC_END, rend, RPC_PACKET_SIZE, NULL, NULL, 0);
378 base->end->next = server;
380 base->start = server;
383 server->pkt_addr =
request->pkt_addr;
384 server->client =
request->client;
385 server->rpc_number =
request->rpc_number;
386 server->size =
request->send_size;
387 server->receive =
request->receive;
388 server->rsize =
request->recv_size;
389 server->rmode =
request->rmode;
392 if (base->thread_id < 0 || base->active != 0)
395 iWakeupThread(base->thread_id);
404 rend->pkt_addr = rdata->pkt_addr;
406 rend->cid = SIF_CMD_RPC_RDATA;
408 iSifSendCmd(SIF_CMD_RPC_END, rend, RPC_PACKET_SIZE, rdata->src, rdata->dest, rdata->size);
411void SifInitRpc(
int mode)
417 static int _rb_count = 0;
418 if (_rb_count != _iop_reboot_count) {
419 _rb_count = _iop_reboot_count;
431 _sif_rpc_data.pkt_table = UNCACHED_SEG(_sif_rpc_data.pkt_table);
432 _sif_rpc_data.rdata_table = UNCACHED_SEG(_sif_rpc_data.rdata_table);
433 _sif_rpc_data.client_table = UNCACHED_SEG(_sif_rpc_data.client_table);
435 _sif_rpc_data.rdata_table_idx = 0;
443 for (rid = 0; rid < len; rid++, packet = (
SifRpcPktHeader_t *)(((
unsigned char *)packet) + RPC_PACKET_SIZE)) {
444 rpc_packet_free(packet);
448 SifAddCmdHandler(SIF_CMD_RPC_END, (
void *)_request_end, &_sif_rpc_data);
449 SifAddCmdHandler(SIF_CMD_RPC_BIND, (
void *)_request_bind, &_sif_rpc_data);
450 SifAddCmdHandler(SIF_CMD_RPC_CALL, (
void *)_request_call, &_sif_rpc_data);
451 SifAddCmdHandler(SIF_CMD_RPC_RDATA, (
void *)_request_rdata, &_sif_rpc_data);
454 if (SifGetReg(SIF_SYSREG_RPCINIT))
457 cmdp = (u32 *)&pkt_table[64];
459 SifSendCmd(SIF_CMD_INIT_CMD, cmdp, 16, NULL, NULL, 0);
463 SifSetReg(SIF_SYSREG_RPCINIT, 1);
473#ifdef F_SifRegisterRpc
476 int sid, SifRpcFunc_t func,
void *buff, SifRpcFunc_t cfunc,
492 if (!(server = qd->link)) {
495 while (server->link != NULL) {
496 server = server->link;
516 if ((server = queue->link) == sd) {
517 queue->link = server->link;
519 while (server != NULL) {
520 if (server->link == sd) {
521 server->link = sd->link;
525 server = server->link;
535#ifdef F_SifSetRpcQueue
543 qd->thread_id = thread_id;
550 if (_sif_rpc_data.active_queue == NULL) {
551 _sif_rpc_data.active_queue = qd;
553 queue = _sif_rpc_data.active_queue;
555 while (queue->next != NULL)
567#ifdef F_SifRemoveRpcQueue
575 if ((queue = _sif_rpc_data.active_queue) == qd) {
576 _sif_rpc_data.active_queue = queue->next;
578 while (queue != NULL) {
579 if (queue->next == qd) {
580 queue->next = qd->next;
594#ifdef F_SifGetNextRequest
603 if (server != NULL) {
605 qd->start = server->next;
616#ifdef F_SifExecRequest
619 if (rid < 0 || rid < rpc_data->client_table_len)
622 return rpc_data->client_table + (rid * RPC_PACKET_SIZE);
631 rec = sd->func(sd->rpc_number, sd->buff, sd->size);
634 SifWriteBackDCache(sd->buff, sd->size);
637 SifWriteBackDCache(rec, sd->rsize);
643 _rpc_get_fpacket2(&_sif_rpc_data, (sd->rid >> 16) & 0xffff);
646 _rpc_get_fpacket(&_sif_rpc_data);
650 rend->client = sd->client;
651 rend->cid = SIF_CMD_RPC_CALL;
654 if (!SifSendCmd(SIF_CMD_RPC_END, rend, RPC_PACKET_SIZE, rec, sd->receive,
664 dmat.dest = sd->receive;
665 dmat.size = sd->rsize;
669 dmat.dest = sd->pkt_addr;
674 while (!SifSetDma(&dmat, 1))
685 while ((server = SifGetNextRequest(qd)))
686 SifExecRequest(server);
693#ifdef F_SifCheckStatRpc
701 if (cd->hdr.rpc_id != (u32)(packet->rpc_id))