port-work; won't compile or even work
[ppcskel.git] / ipc.h
1 /*
2         BootMii - a Free Software replacement for the Nintendo/BroadOn bootloader.
3         Requires mini.
4
5 Copyright (C) 2008, 2009        Haxx Enterprises <bushing@gmail.com>
6 Copyright (C) 2008, 2009        Hector Martin "marcan" <marcan@marcansoft.com>
7 Copyright (C) 2009              Andre Heider "dhewg" <dhewg@wiibrew.org>
8 Copyright (C) 2009              John Kelley <wiidev@kelley.ca>
9 Copyright (C) 2008, 2009        Sven Peter <svenpeter@gmail.com>
10
11 # This code is licensed to you under the terms of the GNU GPL, version 2;
12 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
13 */
14
15 #ifndef __IPC_H__
16 #define __IPC_H__
17
18 /* TODO: It would be nice to somehow link this header file with mini/ipc.h.
19    Until then, if you do make any changes here, you MUST make them here
20    (or vice-versa).  See warnings in mini/ipc.h. --bushing */
21
22 #define IPC_SYS_PING    0x01000000
23 #define IPC_SYS_SLWPING 0x00000000
24 #define IPC_SYS_JUMP    0x00000001
25 #define IPC_SYS_GETVERS 0x00000002
26 #define IPC_SYS_GETGITS 0x00000003
27
28 #define IPC_SYS_WRITE32 0x01000100
29 #define IPC_SYS_WRITE16 0x01000101
30 #define IPC_SYS_WRITE8  0x01000102
31 #define IPC_SYS_READ32  0x01000103
32 #define IPC_SYS_READ16  0x01000104
33 #define IPC_SYS_READ8   0x01000105
34 #define IPC_SYS_SET32   0x01000106
35 #define IPC_SYS_SET16   0x01000107
36 #define IPC_SYS_SET8    0x01000108
37 #define IPC_SYS_CLEAR32 0x01000109
38 #define IPC_SYS_CLEAR16 0x0100010a
39 #define IPC_SYS_CLEAR8  0x0100010b
40 #define IPC_SYS_MASK32  0x0100010c
41 #define IPC_SYS_MASK16  0x0100010d
42 #define IPC_SYS_MASK8   0x0100010e
43
44 #define IPC_NAND_RESET  0x00010000
45 #define IPC_NAND_GETID  0x00010001
46 #define IPC_NAND_READ   0x00010002
47 #define IPC_NAND_WRITE  0x00010003
48 #define IPC_NAND_ERASE  0x00010004
49 #define IPC_NAND_STATUS 0x00010005
50 //#define IPC_NAND_USER0 0x00018000
51 //#define IPC_NAND_USER1 0x00018001
52 // etc.
53
54 #define IPC_SDMMC_ACK   0x00070000
55 #define IPC_SDMMC_READ  0x00070001
56 #define IPC_SDMMC_WRITE 0x00070002
57 #define IPC_SDMMC_STATE 0x00070003
58 #define IPC_SDMMC_SIZE  0x00070004
59
60 #define IPC_SDHC_DISCOVER 0x00020000
61
62 #define IPC_KEYS_GETOTP 0x00030000
63 #define IPC_KEYS_GETEEP 0x00030001
64
65 #define IPC_AES_RESET   0x00040000
66 #define IPC_AES_SETIV   0x00040001
67 #define IPC_AES_SETKEY  0x00040002
68 #define IPC_AES_DECRYPT 0x00040003
69
70 #define IPC_BOOT2_RUN   0x00050000
71 #define IPC_BOOT2_TMD   0x00050001
72
73 #define IPC_PPC_BOOT    0x00060000
74
75 typedef struct {
76         union {
77                 struct {
78                         u8 flags;
79                         u8 device;
80                         u16 req;
81                 };
82                 u32 code;
83         };
84         u32 tag;
85         u32 args[6];
86 } ipc_request;
87
88 extern void *mem2_boundary;
89
90 int ipc_initialize(void);
91 void ipc_shutdown(void);
92
93 void ipc_post(u32 code, u32 tag, u32 num_args, ...);
94
95 void ipc_flush(void);
96
97 ipc_request *ipc_receive(void);
98 ipc_request *ipc_receive_tagged(u32 code, u32 tag);
99
100 ipc_request *ipc_exchange(u32 code, u32 num_args, ...);
101
102 static inline void ipc_sys_write32(u32 addr, u32 x)
103 {
104         ipc_post(IPC_SYS_WRITE32, 0, 2, addr, x);
105 }
106 static inline void ipc_sys_write16(u32 addr, u16 x)
107 {
108         ipc_post(IPC_SYS_WRITE16, 0, 2, addr, x);
109 }
110 static inline void ipc_sys_write8(u32 addr, u8 x)
111 {
112         ipc_post(IPC_SYS_WRITE8, 0, 2, addr, x);
113 }
114
115 static inline u32 ipc_sys_read32(u32 addr)
116 {
117         return ipc_exchange(IPC_SYS_READ32, 1, addr)->args[0];
118 }
119 static inline u16 ipc_sys_read16(u32 addr)
120 {
121         return ipc_exchange(IPC_SYS_READ16, 1, addr)->args[0];
122 }
123 static inline u8 ipc_sys_read8(u32 addr)
124 {
125         return ipc_exchange(IPC_SYS_READ8, 1, addr)->args[0];
126 }
127
128 static inline void ipc_sys_set32(u32 addr, u32 set)
129 {
130         ipc_post(IPC_SYS_SET32, 0, 2, addr, set);
131 }
132 static inline void ipc_sys_set16(u32 addr, u16 set)
133 {
134         ipc_post(IPC_SYS_SET16, 0, 2, addr, set);
135 }
136 static inline void ipc_sys_set8(u32 addr, u8 set)
137 {
138         ipc_post(IPC_SYS_SET8, 0, 2, addr, set);
139 }
140
141 static inline void ipc_sys_clear32(u32 addr, u32 clear)
142 {
143         ipc_post(IPC_SYS_CLEAR32, 0, 2, addr, clear);
144 }
145 static inline void ipc_sys_clear16(u32 addr, u16 clear)
146 {
147         ipc_post(IPC_SYS_CLEAR16, 0, 2, addr, clear);
148 }
149 static inline void ipc_sys_clear8(u32 addr, u8 clear)
150 {
151         ipc_post(IPC_SYS_CLEAR8, 0, 2, addr, clear);
152 }
153
154 static inline void ipc_sys_mask32(u32 addr, u32 clear, u32 set)
155 {
156         ipc_post(IPC_SYS_MASK32, 0, 3, addr, clear, set);
157 }
158 static inline void ipc_sys_mask16(u32 addr, u16 clear, u32 set)
159 {
160         ipc_post(IPC_SYS_MASK16, 0, 3, addr, clear, set);
161 }
162 static inline void ipc_sys_mask8(u32 addr, u8 clear, u32 set)
163 {
164         ipc_post(IPC_SYS_MASK8, 0, 3, addr, clear, set);
165 }
166
167 static inline void ipc_ping(void)
168 {
169         ipc_exchange(IPC_SYS_PING, 0);
170 }
171
172 static inline void ipc_slowping(void)
173 {
174         ipc_exchange(IPC_SYS_SLWPING, 0);
175 }
176
177 static inline u32 ipc_getvers(void)
178 {
179         return ipc_exchange(IPC_SYS_GETVERS, 0)->args[0];
180 }
181
182 #endif
183