11#include "acata_internal.h"
13static int ata_dma_xfer(
acDmaT dma,
int intr, acDmaOp op);
14static void ata_dma_done(
acDmaT dma);
15static void ata_dma_error(
acDmaT dma,
int intr, acDmaState state,
int result);
16static int ata_ops_command(
struct ac_ata_h *atah,
int cmdpri,
int pri);
17static void ata_ops_done(
struct ac_ata_h *atah,
int result);
19static acDmaOpsData ops_8 = {&ata_dma_xfer, &ata_dma_done, &ata_dma_error};
20static struct ac_ata_ops ops_37 = {&ata_ops_command, &ata_ops_done, NULL};
22static int ata_dma_xfer(
acDmaT dma,
int intr, acDmaOp op)
28 if ( dmatmp->ad_state == 31 )
30 dmatmp->ad_result = dmatmp->ad_ata->ac_h.a_size;
31 return op(dma, (
void *)0xB6000000, dmatmp->ad_ata->ac_h.a_buf, dmatmp->ad_ata->ac_h.a_size);
33 thid = dmatmp->ad_thid;
42static void ata_dma_done(
acDmaT dma)
49 thid = dmatmp->ad_thid;
50 dmatmp->ad_state = 127;
55static void ata_dma_error(
acDmaT dma,
int intr, acDmaState state,
int result)
61 thid = dmatmp->ad_thid;
62 dmatmp->ad_state = 1023;
63 dmatmp->ad_result = result;
71 Kprintf(
"acata:A:dma_error: state=%d ret=%d\n", state, result);
74static int ata_ops_command(
struct ac_ata_h *atah,
int cmdpri,
int pri)
78 const acAtaCommandData *cmd;
85 acAtaCommandData *cmd_v36;
93 if ( atah->a_state >= 0x1FFu )
98 if ( (flag & 1) != 0 )
103 dma = acDmaSetup(&dma_data.ad_dma, &ops_8, 4, 8, flag & 4);
104 dma_data.ad_result = 0;
106 dma_data.ad_thid = GetThreadId();
108 dma_data.ad_ata = ata;
109 dma_data.ad_state = 0;
110 ret_v3 = acDmaRequest(dma);
113 printf(
"acata:A:dma_wait: error %d\n", ret_v3);
120 ret_v5 = dma_data.ad_state;
123 if ( (
int)ret_v5 <= 0 )
125 printf(
"acata:A:dma_wait: TIMEDOUT %d\n", ret_v5);
126 acDmaCancel(&dma_data.ad_dma, -116);
141 ChangeThreadPriority(0, cmdpri);
142 cmd = ata->ac_command;
144 flag_v8 = atah->a_flag;
145 *((
volatile acUint16 *)0xB6060000) = flag_v8 & 0x10;
146 *((
volatile acUint16 *)0xB6160000) = (flag_v8 & 2) ^ 2;
147 *((
volatile acUint16 *)0xB6010000) = 0;
153 *(acUint16 *)(((2 * ((data >> 8) & 8) + ((data >> 8) & 7)) << 16) + 0xB6000000) = data & 0xFF;
155 if ( ((data >> 8) & 0xF) == 7 )
160 ChangeThreadPriority(0, pri);
162 if ( atah->a_state >= 0x1FFu )
169 if ( (flag_v8 & 1) != 0 )
171 dma_data.ad_state = 31;
172 acDmaRequest(&dma_data.ad_dma);
173 printf(
"acata:dma start\n");
179 a_buf = (acUint16 *)atah->a_buf;
180 if ( (flag_v8 & 4) != 0 )
184 a_size = atah->a_size;
185 while ( (*((
volatile acUint16 *)0xB6070000) & 0x80) != 0 )
199 xlen_v15 = (
unsigned int)xlen >> 1;
200 xlen_v16 = xlen_v15 - 1;
201 while ( (*((
volatile acUint16 *)0xB6070000) & 8) != 0 )
211 *((
volatile acUint16 *)0xB6000000) = ret_v17;
214 if ( (flag_v8 & 2) != 0 )
216 sr = *((
volatile acUint16 *)0xB6160000);
218 while ( (*((
volatile acUint16 *)0xB6160000) & 0x80) != 0 )
221 if ( SleepThread() != 0 )
223 ret_v20 = *((
volatile acUint16 *)0xB6160000);
228 ret_v20 = *((
volatile acUint16 *)0xB6070000);
229 while ( (*((
volatile acUint16 *)0xB6070000) & 0x80) != 0 )
231 sr = *((
volatile acUint16 *)0xB6070000);
237 if ( (ret_v20 & 8) == 0 )
246 buf_v23 = (acUint16 *)atah->a_buf;
256 if ( (flag_v8 & 2) != 0 )
258 sr_v25 = *((
volatile acUint16 *)0xB6160000);
259 sr_v25 = sr_v25 & 0xFF;
260 while ( (*((
volatile acUint16 *)0xB6160000) & 0x80) != 0 )
265 sr_v25 = *((
volatile acUint16 *)0xB6160000);
270 sr_v25 = *((
volatile acUint16 *)0xB6070000);
271 while ( (*((
volatile acUint16 *)0xB6070000) & 0x80) != 0 )
273 sr_v25 = *((
volatile acUint16 *)0xB6070000);
274 sr_v25 = sr_v25 & 0xFF;
283 xlen_v28 = (
unsigned int)xlen_v27 >> 1;
284 if ( (sr_v25 & 1) != 0 )
286 (void)(*((
volatile acUint16 *)0xB6070000) & 0x80);
287 xlen_v30 = xlen_v28 - 1;
288 while ( (*((
volatile acUint16 *)0xB6070000) & 8) != 0 )
292 *buf_v23 = *((
volatile acUint16 *)0xB6000000);
297 ret_v29 = *((
volatile acUint16 *)0xB6070000) & 0x80;
305 ret_v22 = flag_v8 & 1;
315 v38 = *((
volatile acUint16 *)0xB6160000) & 1;
316 if ( v38 || state >= 511 )
319 "acata:A:dma_iowait: TIMEDOUT %04x:%02x:%02x\n",
321 *((
volatile acUint16 *)0xB6160000),
322 *((
volatile acUint16 *)0xB6010000));
324 acDmaCancel(&dma_data.ad_dma, -116);
330 state = dma_data.ad_state;
331 if ( (*((
volatile acUint16 *)0xB6160000) & 0x80) == 0 && (
int)dma_data.ad_state >= 64 )
333 ret = dma_data.ad_result;
339 if ( dma_data.ad_state == 31 )
349 while ( (*((
volatile acUint16 *)0xB6160000) & 0x81) == 128 )
363 while ( (*((
volatile acUint16 *)0xB6070000) & 0x81) == 128 )
375 printf(
"acata:C:io_done: TIMEDOUT\n");
382 sr_v34 = *((
volatile acUint16 *)0xB6070000);
383 if ( (*((
volatile acUint16 *)0xB6070000) & 1) != 0 )
384 return -((sr_v34 << 8) + *((
volatile acUint16 *)0xB6010000));
385 if ( atah->a_state < 0x1FFu )
394 cmd_v36 = ata->ac_command;
397 return -((sr_v34 << 8) + *((
volatile acUint16 *)0xB6010000));
399 for ( rest_v37 = 6; rest_v37 > 0; --rest_v37 )
401 if ( (((
int)*cmd_v36 >> 12) & 0xF) == 0 )
404 ((((int)*cmd_v36 >> 12) & 0xF) << 12)
405 | ((*(acUint16 *)(((2 * (((
int)*cmd_v36 >> 12) & 8) + (((int)*cmd_v36 >> 12) & 7)) << 16) + 0xB6000000)) & 0xFF);
411static void ata_ops_done(
struct ac_ata_h *atah,
int result)
417 ac_done = ata->ac_done;
419 ac_done(ata, atah->a_arg, result);
422acAtaT acAtaSetup(
acAtaData *ata, acAtaDone done,
void *arg,
unsigned int tmout)
426 ata->ac_h.a_ops = &ops_37;
427 ata->ac_h.a_arg = arg;
428 ata->ac_h.a_tmout = tmout;
429 ata->ac_h.a_state = 0;
430 ata->ac_h.a_flag = 0;
436acAtaCommandData *acAtaReply(
acAtaT ata)
440 return ata->ac_command;
443int acAtaRequest(
acAtaT ata,
int flag, acAtaCommandData *cmd,
int item,
void *buf,
int size)
446 const acAtaCommandData *v8;
449 flag = (flag | 8) ^ 8;
454 if ( (
unsigned int)item >= 7 )
459 ata->ac_h.a_flag = flag;
461 v9 = (
char *)ata + 2 * v7;
465 *((acUint16 *)v9 + 18) = *v8--;
468 ata->ac_h.a_buf = buf;
469 ata->ac_h.a_size = size;
470 return ata_request(&ata->ac_h, WakeupThread);
473int acAtaRequestI(
acAtaT ata,
int flag, acAtaCommandData *cmd,
int item,
void *buf,
int size)
476 const acAtaCommandData *v8;
479 flag = (flag | 8) ^ 8;
484 if ( (
unsigned int)item >= 7 )
489 ata->ac_h.a_flag = flag;
491 v9 = (
char *)ata + 2 * v7;
495 *((acUint16 *)v9 + 18) = *v8--;
498 ata->ac_h.a_buf = buf;
499 ata->ac_h.a_size = size;
500 return ata_request(&ata->ac_h, iWakeupThread);
503int acAtaStatus(
acAtaT ata)
511 state = ata->ac_h.a_state;
512 if ( (
unsigned int)(state - 1) >= 0x7E )
u32 count
start sector of fragmented bd/file