Skip to content

Commit 807103a

Browse files
authored
Merge pull request #859 from uyjulian/rpc_inited_cleanup
Make SIF binding handling more consistent
2 parents 3c93034 + 4568941 commit 807103a

26 files changed

Lines changed: 216 additions & 295 deletions

File tree

ee/kernel/include/iopcontrol.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ extern int SifIopIsAlive(void);
4141
*/
4242
extern int SifIopSync(void);
4343

44+
/**
45+
* @return 1 if IOP reboot count has changed since last call or 0 if not
46+
*/
47+
static inline int HasIopRebootedSinceLastCall(void)
48+
{
49+
static int _rb_count;
50+
extern int _iop_reboot_count;
51+
if (_rb_count != _iop_reboot_count) {
52+
_rb_count = _iop_reboot_count;
53+
return 1;
54+
}
55+
return 0;
56+
}
57+
4458
#ifdef __cplusplus
4559
}
4660
#endif

ee/kernel/src/fileio.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
#define NEWLIB_PORT_AWARE
2222
#include <fileio.h>
2323
#include <string.h>
24+
#include <iopcontrol.h>
2425
#include <fileio-common.h>
2526

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

28-
extern int _iop_reboot_count;
2929
extern SifRpcClientData_t _fio_cd;
30-
extern int _fio_init;
3130
extern int _fio_block_mode;
3231
extern int _fio_io_sema;
3332
extern int _fio_completion_sema;
@@ -41,7 +40,6 @@ void _fio_intr();
4140
SifRpcClientData_t _fio_cd;
4241
int _fio_recv_data[512] __attribute__((aligned(64)));
4342
int _fio_intr_data[32] __attribute__((aligned(64)));
44-
int _fio_init = 0;
4543
int _fio_block_mode;
4644
int _fio_io_sema = -1;
4745
int _fio_completion_sema = -1;
@@ -52,15 +50,10 @@ int fioInit(void)
5250
{
5351
int res;
5452
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-
53+
if (HasIopRebootedSinceLastCall())
6054
fioExit();
61-
}
6255

63-
if (_fio_init)
56+
if (_fio_cd.server)
6457
return 0;
6558

6659
sceSifInitRpc(0);
@@ -87,7 +80,6 @@ int fioInit(void)
8780
if (_fio_io_sema < 0)
8881
return -E_LIB_SEMA_CREATE;
8982

90-
_fio_init = 1;
9183
_fio_block_mode = FIO_WAIT;
9284

9385
return 0;
@@ -151,8 +143,7 @@ void fioSetBlockMode(int blocking)
151143
#ifdef F_fio_exit
152144
void fioExit(void)
153145
{
154-
if (_fio_init) {
155-
_fio_init = 0;
146+
if (_fio_cd.server) {
156147
memset(&_fio_cd, 0, sizeof _fio_cd);
157148
if (_fio_completion_sema >= 0) {
158149
DeleteSema(_fio_completion_sema);

ee/kernel/src/iopheap.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,23 @@
1515
#include "sifrpc.h"
1616
#include "sifcmd.h"
1717
#include "string.h"
18+
#include <iopcontrol.h>
1819
#include "iopheap-common.h"
1920

2021
#include "iopheap.h"
2122

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

2825
#ifdef F_SifInitIopHeap
2926
SifRpcClientData_t _ih_cd;
30-
int _ih_caps = 0;
3127

3228
int SifInitIopHeap()
3329
{
3430
int res;
31+
if (HasIopRebootedSinceLastCall())
32+
SifExitIopHeap();
3533

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);
42-
}
43-
44-
if (_ih_caps)
34+
if (_ih_cd.server)
4535
return 0;
4636

4737
sceSifInitRpc(0);
@@ -52,16 +42,14 @@ int SifInitIopHeap()
5242
if (res < 0)
5343
return -E_SIF_RPC_BIND;
5444

55-
_ih_caps |= IH_C_BOUND;
56-
5745
return 0;
5846
}
5947
#endif
6048

6149
#ifdef F_SifExitIopHeap
6250
void SifExitIopHeap()
6351
{
64-
_ih_caps = 0;
52+
memset(&_ih_cd, 0, sizeof _ih_cd);
6553
}
6654
#endif
6755

ee/kernel/src/loadfile.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,29 @@
2020
#include <kernel.h>
2121
#include <sifrpc.h>
2222
#include <string.h>
23+
#include <iopcontrol.h>
2324

2425
#include <loadfile.h>
2526
#include <iopheap.h>
2627
#include <fcntl.h>
2728
#include <unistd.h>
2829

29-
extern int _iop_reboot_count;
3030
extern SifRpcClientData_t _lf_cd;
31-
extern int _lf_init;
3231

3332
int _SifLoadElfPart(const char *path, const char *secname, t_ExecData *data, int fno);
3433
int _SifLoadModuleBuffer(void *ptr, int arg_len, const char *args, int *modres);
3534

3635
#if defined(F_SifLoadFileInit)
3736
SifRpcClientData_t _lf_cd;
38-
int _lf_init = 0;
3937

4038
int SifLoadFileInit()
4139
{
4240
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;
48-
}
4941

50-
if (_lf_init)
42+
if (HasIopRebootedSinceLastCall())
43+
SifLoadFileExit();
44+
45+
if (_lf_cd.server)
5146
return 0;
5247

5348
sceSifInitRpc(0);
@@ -58,15 +53,13 @@ int SifLoadFileInit()
5853
if (res < 0)
5954
return -E_SIF_RPC_BIND;
6055

61-
_lf_init = 1;
6256
return 0;
6357
}
6458
#endif
6559

6660
#if defined(F_SifLoadFileExit)
6761
void SifLoadFileExit()
6862
{
69-
_lf_init = 0;
7063
memset(&_lf_cd, 0, sizeof _lf_cd);
7164
}
7265
#endif

ee/kernel/src/sifcmd.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <tamtypes.h>
2020
#include <kernel.h>
2121
#include <sifcmd.h>
22+
#include <iopcontrol.h>
2223

2324
#define CMD_PACKET_MAX 128
2425
#define CMD_PACKET_DATA_MAX 112
@@ -50,7 +51,6 @@ struct cmd_data
5051
int *sregs;
5152
} __attribute__((aligned(64)));
5253

53-
extern int _iop_reboot_count;
5454
extern struct cmd_data _sif_cmd_data;
5555
extern unsigned int _SifSendCmd(int cid, int mode, void *pkt, int pktsize, void *src,
5656
void *dest, int size);
@@ -182,7 +182,6 @@ static SifCmdSysHandlerData_t sys_cmd_handlers[SYS_CMD_HANDLER_MAX];
182182
static int sregs[32];
183183

184184
struct cmd_data _sif_cmd_data;
185-
static int init = 0;
186185
static int sif0_id = -1;
187186

188187
struct ca_pkt
@@ -218,17 +217,10 @@ void sceSifInitCmd(void)
218217
{
219218
static struct ca_pkt packet __attribute((aligned(64)));
220219
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);
227-
}
228-
init = 0;
229-
}
220+
if (HasIopRebootedSinceLastCall())
221+
sceSifExitCmd();
230222

231-
if (init)
223+
if (sif0_id >= 0)
232224
return;
233225

234226
DI();
@@ -267,7 +259,6 @@ void sceSifInitCmd(void)
267259
sif0_id = AddDmacHandler(DMAC_SIF0, &_SifCmdIntHandler, 0);
268260
EnableDmac(DMAC_SIF0);
269261

270-
init = 1;
271262

272263
_sif_cmd_data.iopbuf = (void *)sceSifGetReg(SIF_SYSREG_SUBADDR);
273264
if (_sif_cmd_data.iopbuf) {
@@ -293,9 +284,11 @@ void sceSifInitCmd(void)
293284

294285
void sceSifExitCmd(void)
295286
{
296-
DisableDmac(DMAC_SIF0);
297-
RemoveDmacHandler(DMAC_SIF0, sif0_id);
298-
init = 0;
287+
if (sif0_id >= 0) {
288+
DisableDmac(DMAC_SIF0);
289+
RemoveDmacHandler(DMAC_SIF0, sif0_id);
290+
sif0_id = -1;
291+
}
299292
}
300293
#endif
301294

ee/kernel/src/sifrpc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <kernel.h>
2222
#include <sifcmd.h>
2323
#include <sifrpc.h>
24+
#include <iopcontrol.h>
2425

2526
#define RPC_PACKET_SIZE 64
2627

@@ -50,7 +51,6 @@ struct rpc_data
5051
void *active_queue;
5152
} __attribute__((aligned(64)));
5253

53-
extern int _iop_reboot_count;
5454
extern struct rpc_data _sif_rpc_data;
5555

5656
void *_rpc_get_packet(struct rpc_data *rpc_data);
@@ -415,13 +415,10 @@ void sceSifInitRpc(int mode)
415415

416416
(void)mode;
417417

418-
static int _rb_count = 0;
419-
if (_rb_count != _iop_reboot_count) {
420-
_rb_count = _iop_reboot_count;
418+
if (HasIopRebootedSinceLastCall()) {
421419
sceSifExitCmd();
422420
init = 0;
423421
}
424-
425422
if (init)
426423
return;
427424
init = 1;

0 commit comments

Comments
 (0)