WIP: irq handler
[ppcskel.git] / mini_ipc.h
1 /*
2         mini_ipc.h -- public PowerPC-side interface to mini.  Part of the
3         BootMii project.
4
5 Copyright (C) 2009                      Andre Heider "dhewg" <dhewg@wiibrew.org>
6 Copyright (C) 2009                      Haxx Enterprises <bushing@gmail.com>
7 Copyright (C) 2009                      John Kelley <wiidev@kelley.ca>
8 Copyright (C) 2008, 2009        Sven Peter <svenpeter@gmail.com>
9
10 # This code is licensed to you under the terms of the GNU GPL, version 2;
11 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
12 */
13
14 #ifndef __MINI_IPC_H__
15 #define __MINI_IPC_H__
16
17 #define SDHC_ENOCARD    -0x1001
18 #define SDHC_ESTRANGE   -0x1002
19 #define SDHC_EOVERFLOW  -0x1003
20 #define SDHC_ETIMEDOUT  -0x1004
21 #define SDHC_EINVAL     -0x1005
22 #define SDHC_EIO        -0x1006
23
24 #define SDMMC_NO_CARD   1
25 #define SDMMC_NEW_CARD  2
26 #define SDMMC_INSERTED  3
27
28 #define NAND_ECC_OK 0
29 #define NAND_ECC_CORRECTED 1
30 #define NAND_ECC_UNCORRECTABLE -1
31
32 int sd_get_state(void);
33 int sd_protected(void);
34 int sd_mount(void);
35 int sd_select(void);
36 int sd_read(u32 start_block, u32 blk_cnt, void *buffer);
37 int sd_write(u32 start_block, u32 blk_cnt, const void *buffer);
38 u32 sd_getsize(void);
39
40 int ipc_powerpc_boot(const void *addr, u32 len);
41
42 #define TMD_BM_MARK(x) ((u16*)&(x->reserved[4]))
43 // 'BM'
44 #define TMD_BM_MAGIC 0x424d
45
46 typedef struct {
47         u32 type;
48         u8 sig[256];
49         u8 fill[60];
50 } __attribute__((packed)) sig_rsa2048;
51
52 typedef struct {
53         u32 cid;
54         u16 index;
55         u16 type;
56         u64 size;
57         u8 hash[20];
58 } __attribute__((packed)) tmd_content;
59
60 typedef struct {
61         sig_rsa2048 signature;
62         char issuer[0x40];
63         u8 version;
64         u8 ca_crl_version;
65         u8 signer_crl_version;
66         u8 fill2;
67         u64 sys_version;
68         u64 title_id;
69         u32 title_type;
70         u16 group_id;
71         u16 zero;
72         u16 region;
73         u8 ratings[16];
74         u8 reserved[42];
75         u32 access_rights;
76         u16 title_version;
77         u16 num_contents;
78         u16 boot_index;
79         u16 fill3;
80         tmd_content boot_content;
81 } __attribute__((packed)) tmd;
82
83 u32 boot2_run(u32 hi, u32 lo);
84 tmd *boot2_tmd(void);
85
86 typedef struct
87 {
88         u8 boot1_hash[20];
89         u8 common_key[16];
90         u32 ng_id;
91         union { // first two bytes of nand_hmac overlap last two bytes of ng_priv. no clue why
92                 struct {
93                         u8 ng_priv[30];
94                         u8 _wtf1[18];
95                 };
96                 struct {
97                         u8 _wtf2[28];
98                         u8 nand_hmac[20];
99                 };
100         };
101         u8 nand_key[16];
102         u8 rng_key[16];
103         u32 unk1;
104         u32 unk2; // 0x00000007
105 } __attribute__((packed)) otp_t;
106
107 typedef struct
108 {
109         u8 boot2version;
110         u8 unknown1;
111         u8 unknown2;
112         u8 pad;
113         u32 update_tag;
114         u16 checksum;
115 } __attribute__((packed)) eep_ctr_t;
116
117 typedef struct
118 {
119         union {
120                 struct {
121                         u32 ms_key_id;
122                         u32 ca_key_id;
123                         u32 ng_key_id;
124                         u8 ng_sig[60];
125                         eep_ctr_t counters[2];
126                         u8 fill[0x18];
127                         u8 korean_key[16];
128                 };
129                 u8 data[256];
130         };
131 } __attribute__((packed)) seeprom_t;
132
133 void getotp(otp_t *otp);
134 void getseeprom(seeprom_t *seeprom);
135 void getMiniGitVer(char *buf, u16 len);
136         
137 void aes_reset(void);
138 void aes_set_key(u8 *key);
139 void aes_set_iv(u8 *iv);
140 void aes_decrypt(u8 *src, u8 *dst, u32 blocks, u8 keep_iv);
141
142 void nand_reset(void);
143 u32 nand_getid(void);
144 u8 nand_status(void);
145 int nand_read(u32 pageno, void *data, void *ecc);
146 void nand_write(u32 pageno, void *data, void *ecc);
147 void nand_erase(u32 pageno);
148
149 #endif