13#include <irx_imports.h>
15#define MODNAME "ARCADE_ATAD_driver"
16IRX_ID(MODNAME, 1, 80);
28#define sceAtaEntry _start
31static u16 g_sectorbuf[256];
45int do_request(
int flag, acAtaCommandData *cmd,
int item,
void *buf,
int size)
52 ata_ptr = acAtaSetup(&ata, (acAtaDone)on_request_done, &reqd, 5000000u);
54 reqd.thid = GetThreadId();
55 result = acAtaRequest(ata_ptr, flag, cmd, item, buf, size);
65int do_identify(
int device, u32 *total_sectors)
70 acAtaCommandData cmd[4];
72 devident = (device != 0) << 4;
73 memset(g_sectorbuf, 0,
sizeof(g_sectorbuf));
74 cmd[0] = devident | 0x600;
75 cmd[1] = ATA_C_IDENTIFY_DEVICE | 0x700;
76 err = do_request(devident | 2, cmd, 2, g_sectorbuf, 512);
82 printf(
"%d:identify: unexpected error %d\n", device, err);
87 while ( model_no_i < 47 )
89 g_sectorbuf[model_no_i] = ((g_sectorbuf[model_no_i] & 0xFF00) >> 8) | (g_sectorbuf[model_no_i] << 8);
93 *total_sectors = g_sectorbuf[60] + (g_sectorbuf[61] << 16);
94 printf(
"%d:identify:%d: %s\n", device, err, (
const char *)&g_sectorbuf[27]);
98int do_setfeatures(
int device, u8 features)
101 acAtaCommandData cmd[4];
103 cmd[0] = features | 0x200;
104 cmd[1] = 0x03 | 0x100;
105 cmd[2] = ATA_C_SET_FEATURES | 0x700;
106 err = do_request(((device != 0) << 4) | 0x42, cmd, 3, 0, 0);
111 printf(
"%d:setfeatures: unexpected error %d\n", device, err);
119int do_dma_xfer_read(
int device, u32 lba,
void *buf, u32 nsectors)
124 acAtaCommandData cmd[8];
126 devident = (device != 0) << 4;
127 cmd[0] = (nsectors & 0xFF) | 0x200;
128 cmd[1] = (lba & 0xFF) | 0x300;
129 cmd[2] = ((lba & 0xFF00) >> 8) | 0x400;
130 cmd[3] = ((lba & 0xFF0000) >> 16) | 0x500;
131 cmd[4] = devident | 0x40 | ((lba & 0xFF000000) >> 24) | 0x600;
132 cmd[5] = ATA_C_READ_DMA_WITHOUT_RETRIES | 0x700;
133 err = do_request(devident | 0x43, cmd, 6, buf, nsectors << 9);
138 printf(
"%d:read: unexpected error %d\n", device, err);
144 while ( busywait_tmp++ < (
int)(nsectors + 32) )
149int do_dma_xfer_write(
int device, u32 lba,
void *buf, u32 nsectors)
154 acAtaCommandData cmd[8];
156 devident = (device != 0) << 4;
157 cmd[0] = (nsectors & 0xFF) | 0x200;
158 cmd[1] = (lba & 0xFF) | 0x300;
159 cmd[2] = ((lba & 0xFF00) >> 8) | 0x400;
160 cmd[3] = ((lba & 0xFF0000) >> 16) | 0x500;
161 cmd[4] = devident | 0x40 | ((lba & 0xFF000000) >> 24) | 0x600;
162 cmd[5] = ATA_C_WRITE_DMA | 0x700;
163 err = do_request(devident | 0x47, cmd, 6, buf, nsectors << 9);
168 printf(
"%d:read: unexpected error %d\n", device, err);
174 while ( busywait_tmp++ < (
int)(nsectors + 32) )
179int do_flushcache(
int device)
182 acAtaCommandData cmd[4];
186 cmd[2] = ATA_C_FLUSH_CACHE | 0x700;
187 err = do_request(((device != 0) << 4) | 0x42, cmd, 3, 0, 0);
192 printf(
"%d:flushcache: unexpected error %d\n", device, err);
204 u32 total_sectors[2];
206 probe_res = ata_probe((acAtaReg)0xB6000000);
208 g_devinfo.
exists = device == probe_res - 1;
209 if ( device != probe_res - 1 )
214 ident_err = do_identify(device, total_sectors);
217 printf(
"identify error %d\n", ident_err);
220 do_setfeatures(device, 0x22 );
223 printf(
"sceAtaInit %x %x %x\n", device, (
unsigned int)g_devinfo.
exists, (
unsigned int)total_sectors[0]);
227int sceAtaSoftReset(
void)
229 printf(
"sceAtaSoftReset\n");
235 void *buf, u32 blkcount, u16 feature, u16 nsector, u16 sector, u16 lcyl, u16 hcyl, u16 select, u16 command)
246 printf(
"sceAtaExecCmd\n");
251int sceAtaWaitResult(
void)
253 printf(
"sceAtaWaitResult\n");
258int sceAtaGetError(
void)
260 printf(
"sceAtaGetError\n");
265int sceAtaDmaTransfer(
int device,
void *buf, u32 lba, u32 nsectors,
int dir)
270 err = do_dma_xfer_write(device, lba, buf, nsectors);
272 err = do_dma_xfer_read(device, lba, buf, nsectors);
275 printf(
"dma error\n");
282int sceAtaSecuritySetPassword(
int device,
void *password)
287 printf(
"sceAtaSecuritySetPassword\n");
292int sceAtaSecurityUnLock(
int device,
void *password)
297 printf(
"sceAtaSecurityUnLock\n");
301int sceAtaSecurityEraseUnit(
int device)
305 printf(
"sceAtaSecurityEraseUnit\n");
310int sceAtaIdle(
int device,
int period)
315 printf(
"sceAtaIdle\n");
320int sceAtaGetSceId(
int device,
void *data)
325 printf(
"sceAtaGetSceId\n");
330int sceAtaSmartReturnStatus(
int device)
334 printf(
"sceAtaSmartReturnStatus\n");
339int sceAtaSmartSaveAttr(
int device)
343 printf(
"sceAtaSmartSaveAttr\n");
348int sceAtaFlushCache(
int device)
350 do_flushcache(device);
354int sceAtaIdleImmediate(
int device)
358 printf(
"sceAtaIdleImmediate\n");
365 if ( RegisterLibraryEntries(&_exp_atad) )
366 printf(
"atad: module already loaded\n");
367 printf(
"sceAtaEntry\n");
373 printf(
" sceAtaTerminate\n");