Skip to content

Commit

Permalink
Added missing SIF definitions, renamed (EE) PS2IP stack init and dein…
Browse files Browse the repository at this point in the history
…it functions to fit the general naming convention of the PS2SDK, added a function to the EE PS2IP stack for setting the hsync tick rate to allow accurate timing regardless of the video mode, renamed SifIopIsAlive to SifCheckInit (As SCE called its IOP-side equivalent), and made a partial rollback: undid the change of SIFCMD and SIFRPC functions to have SCE-style naming

The original plan was to standardize the naming convention of SIF functions between the EE and IOP, but that now doesn't seem as good as I hoped because a lot of EE-side code aren't named in that way.
If the other kernel parts (e.g. iopheap service) that were related to the SIF were left to use the homebrew naming convention, then the new SIFCMD and SIFRPC functions will stick out like a sore thumb. :(
But if I did change everything, that will result in a lot of work.
  • Loading branch information
sp193 committed Mar 5, 2015
1 parent d594e06 commit c6cd5b3
Show file tree
Hide file tree
Showing 50 changed files with 538 additions and 516 deletions.
2 changes: 1 addition & 1 deletion ee/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ IOPHEAP_OBJS = SifInitIopHeap.o SifExitIopHeap.o SifAllocIopHeap.o \
SifFreeIopHeap.o SifLoadIopHeap.o
IOPHEAP_OBJS := $(IOPHEAP_OBJS:%=$(EE_OBJS_DIR)%)

IOPCONTROL_OBJS = SifIopReboot.o SifIopReset.o SifIopIsAlive.o SifIopSync.o __iop_control_internals.o
IOPCONTROL_OBJS = SifIopReboot.o SifIopReset.o SifCheckInit.o SifIopSync.o __iop_control_internals.o
IOPCONTROL_OBJS := $(IOPCONTROL_OBJS:%=$(EE_OBJS_DIR)%)

GLUE_OBJS = DIntr.o EIntr.o EnableIntc.o DisableIntc.o EnableDmac.o DisableDmac.o \
Expand Down
30 changes: 14 additions & 16 deletions ee/kernel/include/sifcmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ typedef struct t_SifCmdHeader
#define SIF_CMD_SET_SREG (SIF_CMD_ID_SYSTEM | 1)
#define SIF_CMD_INIT_CMD (SIF_CMD_ID_SYSTEM | 2)
#define SIF_CMD_RESET_CMD (SIF_CMD_ID_SYSTEM | 3)
#define SIF_CMD_RPC_END (SIF_CMD_ID_SYSTEM | 8)
#define SIF_CMD_RPC_BIND (SIF_CMD_ID_SYSTEM | 9)
#define SIF_CMD_RPC_CALL (SIF_CMD_ID_SYSTEM | 10)
#define SIF_CMD_RPC_RDATA (SIF_CMD_ID_SYSTEM | 12)

//System SREG
#define SIF_SREG_RPCINIT 0

//Structure for remotely (over the SIF) changing the value of a software register (SREG).
//There are 32 software registers (0 - 31). Registers 0-7 are used by the system.
Expand All @@ -51,30 +58,21 @@ typedef struct t_SifCmdHandlerData
void *harg;
} SifCmdHandlerData_t;

unsigned int sceSifSendCmd(int cmd, void *packet, int packet_size, void *src_extra,
unsigned int SifSendCmd(int cmd, void *packet, int packet_size, void *src_extra,
void *dest_extra, int size_extra);
unsigned int isceSifSendCmd(int cmd, void *packet, int packet_size, void *src_extra,
unsigned int iSifSendCmd(int cmd, void *packet, int packet_size, void *src_extra,
void *dest_extra, int size_extra);
void sceSifAddCmdHandler(int cid, SifCmdHandler_t handler, void *harg);
void sceSifInitCmd(void);
void sceSifExitCmd(void);
int sceSifGetSreg(int index);
void SifAddCmdHandler(int cid, SifCmdHandler_t handler, void *harg);
void SifInitCmd(void);
void SifExitCmd(void);
int SifGetSreg(int index);

void sceSifWriteBackDCache(void *ptr, int size); //EE only
void SifWriteBackDCache(void *ptr, int size); //EE only

//Send mode bits
#define SIF_CMD_M_INTR 0x01 //Called within an interrupt context
#define SIF_CMD_M_WBDC 0x04 //Write back D-cache for extended data

//For backward-compatibility
#define SifInitCmd sceSifInitCmd
#define SifExitCmd sceSifExitCmd
#define SifSendCmd sceSifSendCmd
#define iSifSendCmd isceSifSendCmd
#define SifAddCmdHandler sceSifAddCmdHandler
#define SifGetSreg sceSifGetSreg
#define SifWriteBackDCache sceSifWriteBackDCache

#ifdef __cplusplus
}
#endif
Expand Down
24 changes: 16 additions & 8 deletions ee/kernel/include/sifdma.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,25 @@ extern "C" {

#define SIF_DMA_ERT 0x40

#define SIF_REG_ID_SYSTEM 0x80000000

enum _sif_regs {
SIF_REG_MAINADDR = 1,
SIF_REG_SUBADDR,
SIF_REG_MSFLAG,
SIF_REG_SMFLAG
SIF_REG_MAINADDR = 1, //Main -> sub-CPU command buffer (MSCOM)
SIF_REG_SUBADDR, //Sub -> main-CPU command buffer (SMCOM)
SIF_REG_MSFLAG, //Main -> sub-CPU flag (MSFLAG)
SIF_REG_SMFLAG, //Sub -> main-CPU flag (SMFLAG)

//Used with the EE kernel. Not actually physical registers like the above, but are implemented in software.
SIF_SYSREG_SUBADDR = SIF_REG_ID_SYSTEM|0,
SIF_SYSREG_MAINADDR,
SIF_SYSREG_RPCINIT,
};

//Status bits for the SM and MS SIF registers
#define SIF_STAT_SIFINIT 0x10000 //SIF initialized
#define SIF_STAT_CMDINIT 0x20000 //SIFCMD initialized
#define SIF_STAT_BOOTEND 0x40000 //Bootup completed

typedef struct t_SifDmaTransfer
{
void *src,
Expand All @@ -43,10 +55,6 @@ typedef struct t_SifDmaTransfer
u32 SifSetDma(SifDmaTransfer_t *sdd, s32 len);
s32 SifDmaStat(u32 id);

//For compatibility
#define sceSifSetDma SifSetDma
#define sceSifDmaStat SifDmaStat

#ifdef __cplusplus
}
#endif
Expand Down
37 changes: 12 additions & 25 deletions ee/kernel/include/sifrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,46 +152,33 @@ typedef struct t_SifRpcDataQueue
struct t_SifRpcDataQueue *next; /* 05 */
} SifRpcDataQueue_t;

void sceSifInitRpc(int mode);
void sceSifExitRpc(void);
void SifInitRpc(int mode);
void SifExitRpc(void);

/* SIF RPC client API */
int sceSifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode);
int sceSifCallRpc(SifRpcClientData_t *client, int rpc_number, int mode,
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode);
int SifCallRpc(SifRpcClientData_t *client, int rpc_number, int mode,
void *send, int ssize, void *receive, int rsize,
SifRpcEndFunc_t end_function, void *end_param);
int sceSifRpcGetOtherData(SifRpcReceiveData_t *rd, void *src, void *dest,
int SifRpcGetOtherData(SifRpcReceiveData_t *rd, void *src, void *dest,
int size, int mode);

int sceSifCheckStatRpc(SifRpcClientData_t *cd);
int SifCheckStatRpc(SifRpcClientData_t *cd);

/* SIF RPC server API */
SifRpcDataQueue_t *
sceSifSetRpcQueue(SifRpcDataQueue_t *q, int thread_id);
SifSetRpcQueue(SifRpcDataQueue_t *q, int thread_id);

SifRpcServerData_t *
sceSifRegisterRpc(SifRpcServerData_t *srv,
SifRegisterRpc(SifRpcServerData_t *srv,
int sid, SifRpcFunc_t func, void *buff, SifRpcFunc_t cfunc,
void *cbuff, SifRpcDataQueue_t *qd);

SifRpcServerData_t *
sceSifGetNextRequest(SifRpcDataQueue_t *qd);

void sceSifExecRequest(SifRpcServerData_t *srv);
void sceSifRpcLoop(SifRpcDataQueue_t *q);

// For backward-compatibility
#define SifInitRpc sceSifInitRpc
#define SifExitRpc sceSifExitRpc
#define SifBindRpc sceSifBindRpc
#define SifCallRpc sceSifCallRpc
#define SifRpcGetOtherData sceSifGetOtherData
#define SifCheckStatRpc sceSifCheckStatRpc
#define SifSetRpcQueue sceSifSetRpcQueue
#define SifRegisterRpc sceSifRegisterRpc
#define SifGetNextRequest sceSifGetNextRequest
#define SifExecRequest sceSifExecRequest
#define SifRpcLoop sceSifRpcLoop
SifGetNextRequest(SifRpcDataQueue_t *qd);

void SifExecRequest(SifRpcServerData_t *srv);
void SifRpcLoop(SifRpcDataQueue_t *q);

#ifdef __cplusplus
}
Expand Down
42 changes: 21 additions & 21 deletions ee/kernel/src/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ int fioInit(void)
if (_fio_init)
return 0;

sceSifInitRpc(0);
SifInitRpc(0);

while (((res = sceSifBindRpc(&_fio_cd, 0x80000001, 0)) >= 0) &&
while (((res = SifBindRpc(&_fio_cd, 0x80000001, 0)) >= 0) &&
(_fio_cd.server == NULL))
nopdelay();

Expand Down Expand Up @@ -218,7 +218,7 @@ int fioOpen(const char *name, int mode)

/* TODO: All of these can be cleaned up (get rid of res), and an
appropiate error from errno.h be used instead. */
if ((res = sceSifCallRpc(&_fio_cd, FIO_F_OPEN, _fio_block_mode, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_OPEN, _fio_block_mode, &arg, sizeof arg,
_fio_recv_data, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=(_fio_block_mode == FIO_NOWAIT)?0:_fio_recv_data[0];
Expand Down Expand Up @@ -248,7 +248,7 @@ int fioClose(int fd)

arg.fd = fd;

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_CLOSE, 0, &arg, 4, &arg, 4,
if ((res = SifCallRpc(&_fio_cd, FIO_F_CLOSE, 0, &arg, 4, &arg, 4,
(void *)_fio_intr, NULL)) >= 0)
{
result=arg.result;
Expand Down Expand Up @@ -306,9 +306,9 @@ int fioRead(int fd, void *ptr, int size)
arg.read_data = (struct _fio_read_data *)_fio_intr_data;

if (!IS_UNCACHED_SEG(ptr))
sceSifWriteBackDCache(ptr, size);
SifWriteBackDCache(ptr, size);

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_READ, _fio_block_mode, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_READ, _fio_block_mode, &arg, sizeof arg,
_fio_recv_data, 4, (void *)_fio_read_intr, _fio_intr_data)) >= 0)
{
result=(_fio_block_mode == FIO_NOWAIT)?0:_fio_recv_data[0];
Expand Down Expand Up @@ -361,9 +361,9 @@ int fioWrite(int fd, const void *ptr, int size)
memcpy(arg.aligned, ptr, mis);

if (!IS_UNCACHED_SEG(ptr))
sceSifWriteBackDCache((void*)ptr, size);
SifWriteBackDCache((void*)ptr, size);

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_WRITE, _fio_block_mode, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_WRITE, _fio_block_mode, &arg, sizeof arg,
_fio_recv_data, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=(_fio_block_mode == FIO_NOWAIT)?0:_fio_recv_data[0];
Expand Down Expand Up @@ -404,7 +404,7 @@ int fioLseek(int fd, int offset, int whence)
arg.offset = offset;
arg.whence = whence;

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_LSEEK, 0, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_LSEEK, 0, &arg, sizeof arg,
&arg, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=arg.p.result;
Expand Down Expand Up @@ -445,7 +445,7 @@ int fioIoctl(int fd, int request, void *data)
arg.request = request;
memcpy(arg.data, data, 1024);

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_IOCTL, 0, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_IOCTL, 0, &arg, sizeof arg,
&arg, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=arg.p.result;
Expand Down Expand Up @@ -479,7 +479,7 @@ int fioRemove(const char *name)
strncpy(arg.path, name, FIO_PATH_MAX - 1);
arg.path[FIO_PATH_MAX - 1] = 0;

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_REMOVE, 0, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_REMOVE, 0, &arg, sizeof arg,
&arg, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=arg.result;
Expand Down Expand Up @@ -513,7 +513,7 @@ int fioMkdir(const char* path)
strncpy(arg.path, path, FIO_PATH_MAX - 1);
arg.path[FIO_PATH_MAX - 1] = 0;

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_MKDIR, 0, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_MKDIR, 0, &arg, sizeof arg,
&arg, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=arg.result;
Expand Down Expand Up @@ -547,7 +547,7 @@ int fioRmdir(const char* dirname)
strncpy(arg.path, dirname, FIO_PATH_MAX - 1);
arg.path[FIO_PATH_MAX - 1] = 0;

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_RMDIR, 0, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_RMDIR, 0, &arg, sizeof arg,
&arg, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=arg.result;
Expand Down Expand Up @@ -628,7 +628,7 @@ int fioDopen(const char *name)
strncpy(arg.name, name, FIO_PATH_MAX - 1);
arg.name[FIO_PATH_MAX - 1] = 0;

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_DOPEN, 0, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_DOPEN, 0, &arg, sizeof arg,
&arg, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=arg.result;
Expand Down Expand Up @@ -661,7 +661,7 @@ int fioDclose(int fd)

arg.fd = fd;

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_DCLOSE, 0, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_DCLOSE, 0, &arg, sizeof arg,
&arg, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=arg.result;
Expand Down Expand Up @@ -701,9 +701,9 @@ int fioDread(int fd, fio_dirent_t *buf)
arg.buf = buf;

if (!IS_UNCACHED_SEG(buf))
sceSifWriteBackDCache(buf, sizeof(fio_dirent_t));
SifWriteBackDCache(buf, sizeof(fio_dirent_t));

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_DREAD, 0, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_DREAD, 0, &arg, sizeof arg,
&arg, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=arg.p.result;
Expand Down Expand Up @@ -744,9 +744,9 @@ int fioGetstat(const char *name, fio_stat_t *buf)
arg.name[FIO_PATH_MAX - 1] = 0;

if (!IS_UNCACHED_SEG(buf))
sceSifWriteBackDCache(buf, sizeof(fio_stat_t));
SifWriteBackDCache(buf, sizeof(fio_stat_t));

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_GETSTAT, 0, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_GETSTAT, 0, &arg, sizeof arg,
&arg, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=arg.p.result;
Expand Down Expand Up @@ -788,7 +788,7 @@ int fioChstat(const char *name, fio_stat_t *buf, u32 cbit)
strncpy(arg.name, name, FIO_PATH_MAX - 1);
arg.name[FIO_PATH_MAX - 1] = 0;

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_CHSTAT, 0, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_CHSTAT, 0, &arg, sizeof arg,
&arg, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=arg.p.result;
Expand Down Expand Up @@ -822,7 +822,7 @@ int fioFormat(const char *name)
strncpy(arg.path, name, FIO_PATH_MAX - 1);
arg.path[FIO_PATH_MAX - 1] = 0;

if ((res = sceSifCallRpc(&_fio_cd, FIO_F_FORMAT, 0, &arg, sizeof arg,
if ((res = SifCallRpc(&_fio_cd, FIO_F_FORMAT, 0, &arg, sizeof arg,
&arg, 4, (void *)_fio_intr, NULL)) >= 0)
{
result=arg.result;
Expand Down
31 changes: 16 additions & 15 deletions ee/kernel/src/iopcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <tamtypes.h>
#include <kernel.h>
#include <sifcmd.h>
#include <sifrpc.h>
#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -49,7 +50,7 @@ int SifIopReset(const char *arg, int mode)
memset(&reset_pkt, 0, sizeof reset_pkt);

reset_pkt.header.size = sizeof reset_pkt;
reset_pkt.header.cid = 0x80000003;
reset_pkt.header.cid = SIF_CMD_RESET_CMD;

reset_pkt.mode = mode;
if (arg != NULL) {
Expand All @@ -60,20 +61,20 @@ int SifIopReset(const char *arg, int mode)
}

dmat.src = &reset_pkt;
dmat.dest = (void *)SifGetReg(SIF_CMD_CHANGE_SADDR);
dmat.dest = (void *)SifGetReg(SIF_SYSREG_SUBADDR);
dmat.size = sizeof(reset_pkt);
dmat.attr = 0x40 | SIF_DMA_INT_O;
sceSifWriteBackDCache(&reset_pkt, sizeof(reset_pkt));
dmat.attr = SIF_DMA_ERT | SIF_DMA_INT_O;
SifWriteBackDCache(&reset_pkt, sizeof(reset_pkt));

SifSetReg(SIF_REG_SMFLAG, 0x40000);
SifSetReg(SIF_REG_SMFLAG, SIF_STAT_BOOTEND);

if (!SifSetDma(&dmat, 1))
return 0;

SifSetReg(SIF_REG_SMFLAG, 0x10000);
SifSetReg(SIF_REG_SMFLAG, 0x20000);
SifSetReg(SIF_CMD_INIT_CMD, 0);
SifSetReg(SIF_CMD_CHANGE_SADDR, 0);
SifSetReg(SIF_REG_SMFLAG, SIF_STAT_SIFINIT);
SifSetReg(SIF_REG_SMFLAG, SIF_STAT_CMDINIT);
SifSetReg(SIF_SYSREG_RPCINIT, (int)NULL);
SifSetReg(SIF_SYSREG_SUBADDR, (int)NULL);

return 1;
}
Expand All @@ -90,8 +91,8 @@ int SifIopReboot(const char* arg)
return 0;
}

sceSifInitRpc(0);
sceSifExitRpc();
SifInitRpc(0);
SifExitRpc();

strcpy(param_str, "rom0:UDNL ");
strcat(param_str, arg);
Expand All @@ -100,16 +101,16 @@ int SifIopReboot(const char* arg)
}
#endif

#ifdef F_SifIopIsAlive
int SifIopIsAlive()
#ifdef F_SifCheckInit
int SifCheckInit(void)
{
return ((SifGetReg(SIF_REG_SMFLAG) & 0x10000) != 0);
return ((SifGetReg(SIF_REG_SMFLAG) & SIF_STAT_SIFINIT) != 0);
}
#endif

#ifdef F_SifIopSync
int SifIopSync()
{
return((SifGetReg(SIF_REG_SMFLAG) & 0x40000) != 0);
return((SifGetReg(SIF_REG_SMFLAG) & SIF_STAT_BOOTEND) != 0);
}
#endif
Loading

0 comments on commit c6cd5b3

Please sign in to comment.