Skip to content

Commit 5b1bc49

Browse files
committed
cleanup: Make SIF binding handling more consistent
If IOP reboot, deinit and re-bind Use server member of SIF client data as check for initialization
1 parent f388f51 commit 5b1bc49

24 files changed

Lines changed: 303 additions & 278 deletions

File tree

ee/kernel/src/fileio.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525

2626
#define D(fmt, args...) printf("(%s:%s:%i):" #fmt, __FILE__, __FUNCTION__, __LINE__, ##args)
2727

28-
extern int _iop_reboot_count;
2928
extern SifRpcClientData_t _fio_cd;
30-
extern int _fio_init;
3129
extern int _fio_block_mode;
3230
extern int _fio_io_sema;
3331
extern int _fio_completion_sema;
@@ -41,7 +39,6 @@ void _fio_intr();
4139
SifRpcClientData_t _fio_cd;
4240
int _fio_recv_data[512] __attribute__((aligned(64)));
4341
int _fio_intr_data[32] __attribute__((aligned(64)));
44-
int _fio_init = 0;
4542
int _fio_block_mode;
4643
int _fio_io_sema = -1;
4744
int _fio_completion_sema = -1;
@@ -52,15 +49,16 @@ int fioInit(void)
5249
{
5350
int res;
5451
ee_sema_t sema;
55-
static int _rb_count = 0;
56-
57-
if (_rb_count != _iop_reboot_count) {
58-
_rb_count = _iop_reboot_count;
59-
60-
fioExit();
52+
{
53+
static int _rb_count;
54+
extern int _iop_reboot_count;
55+
if (_rb_count != _iop_reboot_count) {
56+
_rb_count = _iop_reboot_count;
57+
fioExit();
58+
}
6159
}
6260

63-
if (_fio_init)
61+
if (_fio_cd.server)
6462
return 0;
6563

6664
sceSifInitRpc(0);
@@ -87,7 +85,6 @@ int fioInit(void)
8785
if (_fio_io_sema < 0)
8886
return -E_LIB_SEMA_CREATE;
8987

90-
_fio_init = 1;
9188
_fio_block_mode = FIO_WAIT;
9289

9390
return 0;
@@ -151,8 +148,7 @@ void fioSetBlockMode(int blocking)
151148
#ifdef F_fio_exit
152149
void fioExit(void)
153150
{
154-
if (_fio_init) {
155-
_fio_init = 0;
151+
if (_fio_cd.server) {
156152
memset(&_fio_cd, 0, sizeof _fio_cd);
157153
if (_fio_completion_sema >= 0) {
158154
DeleteSema(_fio_completion_sema);

ee/kernel/src/iopheap.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,24 @@
1919

2020
#include "iopheap.h"
2121

22-
#define IH_C_BOUND 0x0001
23-
24-
extern int _iop_reboot_count;
2522
extern SifRpcClientData_t _ih_cd;
26-
extern int _ih_caps;
2723

2824
#ifdef F_SifInitIopHeap
2925
SifRpcClientData_t _ih_cd;
30-
int _ih_caps = 0;
3126

3227
int SifInitIopHeap()
3328
{
3429
int res;
35-
36-
static int _rb_count = 0;
37-
if (_rb_count != _iop_reboot_count) {
38-
_rb_count = _iop_reboot_count;
39-
memset(&_ih_cd, 0, sizeof _ih_cd);
40-
_ih_caps = 0;
41-
memset(&_ih_caps, 0, sizeof _ih_caps);
30+
{
31+
static int _rb_count;
32+
extern int _iop_reboot_count;
33+
if (_rb_count != _iop_reboot_count) {
34+
_rb_count = _iop_reboot_count;
35+
SifExitIopHeap();
36+
}
4237
}
4338

44-
if (_ih_caps)
39+
if (_ih_cd.server)
4540
return 0;
4641

4742
sceSifInitRpc(0);
@@ -52,16 +47,14 @@ int SifInitIopHeap()
5247
if (res < 0)
5348
return -E_SIF_RPC_BIND;
5449

55-
_ih_caps |= IH_C_BOUND;
56-
5750
return 0;
5851
}
5952
#endif
6053

6154
#ifdef F_SifExitIopHeap
6255
void SifExitIopHeap()
6356
{
64-
_ih_caps = 0;
57+
memset(&_ih_cd, 0, sizeof _ih_cd);
6558
}
6659
#endif
6760

ee/kernel/src/loadfile.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,27 @@
2626
#include <fcntl.h>
2727
#include <unistd.h>
2828

29-
extern int _iop_reboot_count;
3029
extern SifRpcClientData_t _lf_cd;
31-
extern int _lf_init;
3230

3331
int _SifLoadElfPart(const char *path, const char *secname, t_ExecData *data, int fno);
3432
int _SifLoadModuleBuffer(void *ptr, int arg_len, const char *args, int *modres);
3533

3634
#if defined(F_SifLoadFileInit)
3735
SifRpcClientData_t _lf_cd;
38-
int _lf_init = 0;
3936

4037
int SifLoadFileInit()
4138
{
4239
int res;
43-
static int _rb_count = 0;
44-
if (_rb_count != _iop_reboot_count) {
45-
_rb_count = _iop_reboot_count;
46-
memset(&_lf_cd, 0, sizeof _lf_cd);
47-
_lf_init = 0;
40+
{
41+
static int _rb_count;
42+
extern int _iop_reboot_count;
43+
if (_rb_count != _iop_reboot_count) {
44+
_rb_count = _iop_reboot_count;
45+
SifLoadFileExit();
46+
}
4847
}
4948

50-
if (_lf_init)
49+
if (_lf_cd.server)
5150
return 0;
5251

5352
sceSifInitRpc(0);
@@ -58,15 +57,13 @@ int SifLoadFileInit()
5857
if (res < 0)
5958
return -E_SIF_RPC_BIND;
6059

61-
_lf_init = 1;
6260
return 0;
6361
}
6462
#endif
6563

6664
#if defined(F_SifLoadFileExit)
6765
void SifLoadFileExit()
6866
{
69-
_lf_init = 0;
7067
memset(&_lf_cd, 0, sizeof _lf_cd);
7168
}
7269
#endif

ee/kernel/src/sifcmd.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ struct cmd_data
5050
int *sregs;
5151
} __attribute__((aligned(64)));
5252

53-
extern int _iop_reboot_count;
5453
extern struct cmd_data _sif_cmd_data;
5554
extern unsigned int _SifSendCmd(int cid, int mode, void *pkt, int pktsize, void *src,
5655
void *dest, int size);
@@ -182,7 +181,6 @@ static SifCmdSysHandlerData_t sys_cmd_handlers[SYS_CMD_HANDLER_MAX];
182181
static int sregs[32];
183182

184183
struct cmd_data _sif_cmd_data;
185-
static int init = 0;
186184
static int sif0_id = -1;
187185

188186
struct ca_pkt
@@ -218,17 +216,16 @@ void sceSifInitCmd(void)
218216
{
219217
static struct ca_pkt packet __attribute((aligned(64)));
220218
int i;
221-
static int _rb_count = 0;
222-
if (_rb_count != _iop_reboot_count) {
223-
_rb_count = _iop_reboot_count;
224-
if (sif0_id >= 0) {
225-
DisableDmac(DMAC_SIF0);
226-
RemoveDmacHandler(DMAC_SIF0, sif0_id);
219+
{
220+
static int _rb_count;
221+
extern int _iop_reboot_count;
222+
if (_rb_count != _iop_reboot_count) {
223+
_rb_count = _iop_reboot_count;
224+
sceSifExitCmd();
227225
}
228-
init = 0;
229226
}
230227

231-
if (init)
228+
if (sif0_id >= 0)
232229
return;
233230

234231
DI();
@@ -267,7 +264,6 @@ void sceSifInitCmd(void)
267264
sif0_id = AddDmacHandler(DMAC_SIF0, &_SifCmdIntHandler, 0);
268265
EnableDmac(DMAC_SIF0);
269266

270-
init = 1;
271267

272268
_sif_cmd_data.iopbuf = (void *)sceSifGetReg(SIF_SYSREG_SUBADDR);
273269
if (_sif_cmd_data.iopbuf) {
@@ -293,9 +289,11 @@ void sceSifInitCmd(void)
293289

294290
void sceSifExitCmd(void)
295291
{
296-
DisableDmac(DMAC_SIF0);
297-
RemoveDmacHandler(DMAC_SIF0, sif0_id);
298-
init = 0;
292+
if (sif0_id >= 0) {
293+
DisableDmac(DMAC_SIF0);
294+
RemoveDmacHandler(DMAC_SIF0, sif0_id);
295+
sif0_id = -1;
296+
}
299297
}
300298
#endif
301299

ee/kernel/src/sifrpc.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ struct rpc_data
5050
void *active_queue;
5151
} __attribute__((aligned(64)));
5252

53-
extern int _iop_reboot_count;
5453
extern struct rpc_data _sif_rpc_data;
5554

5655
void *_rpc_get_packet(struct rpc_data *rpc_data);
@@ -415,11 +414,14 @@ void sceSifInitRpc(int mode)
415414

416415
(void)mode;
417416

418-
static int _rb_count = 0;
419-
if (_rb_count != _iop_reboot_count) {
420-
_rb_count = _iop_reboot_count;
421-
sceSifExitCmd();
422-
init = 0;
417+
{
418+
static int _rb_count;
419+
extern int _iop_reboot_count;
420+
if (_rb_count != _iop_reboot_count) {
421+
_rb_count = _iop_reboot_count;
422+
sceSifExitCmd();
423+
init = 0;
424+
}
423425
}
424426

425427
if (init)

0 commit comments

Comments
 (0)