ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
iopcontrol.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # (C)2001, Gustavo Scotti (gustavo@scotti.com)
7 # (c) 2003 Marcus R. Brown (mrbrown@0xd6.org)
8 # Licenced under Academic Free License version 2.0
9 # Review ps2sdk README & LICENSE files for further details.
10 */
11 
17 #include <tamtypes.h>
18 #include <kernel.h>
19 #include <sifcmd.h>
20 #include <sifrpc.h>
21 #include <string.h>
22 #include <stdio.h>
23 
24 #include <iopcontrol.h>
25 
26 #ifdef F___iop_control_internals
27 int _iop_reboot_count = 0;
28 #endif
29 
30 extern int _iop_reboot_count;
31 
32 #ifdef F_SifIopReset
33 
34 int SifIopReset(const char *arg, int mode)
35 {
36  static SifCmdResetData_t reset_pkt __attribute__((aligned(64)));
37  struct t_SifDmaTransfer dmat;
38  int arglen;
39 
40  _iop_reboot_count++; // increment reboot counter to allow RPC clients to detect unbinding!
41 
42  SifStopDma(); //Stop DMA transfers across SIF0 (IOP -> EE).
43 
44  /* The original did not null-terminate, had no bounds-checking and counted the characters as it copied.
45  The IOP side will only copy up to arglen characters. */
46  if(arg != NULL)
47  {
48  for(arglen = 0; arg[arglen] != '\0'; arglen++)
49  reset_pkt.arg[arglen] = arg[arglen];
50  }
51  else
52  { //While NULL was not officially supported, do this for backward-compatibility with old homebrew projects.
53  arglen = 0;
54  }
55 
56  reset_pkt.header.psize = sizeof reset_pkt; //dsize is not initialized (and not processed, even on the IOP).
57  reset_pkt.header.cid = SIF_CMD_RESET_CMD;
58  reset_pkt.arglen = arglen;
59  reset_pkt.mode = mode;
60 
61  dmat.src = &reset_pkt;
62  dmat.dest = (void *)SifGetReg(SIF_SYSREG_SUBADDR);
63  dmat.size = sizeof(reset_pkt);
64  dmat.attr = SIF_DMA_ERT | SIF_DMA_INT_O;
65  SifWriteBackDCache(&reset_pkt, sizeof(reset_pkt));
66 
68 
69  if (!SifSetDma(&dmat, 1))
70  return 0;
71 
76 
77  return 1;
78 }
79 #endif
80 
81 #ifdef F_SifIopReboot
82 int SifIopReboot(const char* arg)
83 {
84  char param_str[RESET_ARG_MAX+1];
85 
86  if(strlen(arg) + 11 > RESET_ARG_MAX)
87  {
88  printf("too long parameter \'%s\'\n", arg);
89  return 0;
90  }
91 
92  SifInitRpc(0);
93  SifExitRpc();
94 
95  strcpy(param_str, "rom0:UDNL ");
96  strcat(param_str, arg);
97 
98  return SifIopReset(param_str, 0);
99 }
100 #endif
101 
102 #ifdef F_SifIopIsAlive
103 int SifIopIsAlive(void)
104 {
105  return ((SifGetReg(SIF_REG_SMFLAG) & SIF_STAT_SIFINIT) != 0);
106 }
107 #endif
108 
109 #ifdef F_SifIopSync
110 int SifIopSync()
111 {
112  return((SifGetReg(SIF_REG_SMFLAG) & SIF_STAT_BOOTEND) != 0);
113 }
114 #endif
int _iop_reboot_count
int SifIopIsAlive(void)
int SifIopReboot(const char *arg)
int SifIopReset(const char *arg, int mode)
int SifIopSync(void)
u32 SifSetDma(SifDmaTransfer_t *sdd, s32 len)
void SifStopDma(void)
int SifSetReg(u32 register_num, int register_value)
int SifGetReg(u32 register_num)
s32 mode
Definition: rpc_client.c:15
void SifWriteBackDCache(void *ptr, int size)
#define SIF_CMD_RESET_CMD
Definition: sifcmd.h:42
#define RESET_ARG_MAX
Definition: sifcmd.h:72
#define SIF_STAT_CMDINIT
Definition: sifdma.h:48
#define SIF_DMA_ERT
Definition: sifdma.h:24
#define SIF_DMA_INT_O
Definition: sifdma.h:22
#define SIF_STAT_BOOTEND
Definition: sifdma.h:50
@ SIF_SYSREG_SUBADDR
Definition: sifdma.h:39
@ SIF_SYSREG_RPCINIT
Definition: sifdma.h:41
@ SIF_REG_SMFLAG
Definition: sifdma.h:36
#define SIF_STAT_SIFINIT
Definition: sifdma.h:46
void SifInitRpc(int mode)
void SifExitRpc(void)
#define NULL
Definition: tamtypes.h:91