11#include "acata_internal.h"
23 Kprintf(
"acata:timer_done\n");
26 iReleaseWaitThread(thid);
29static void ata_thread(
void *arg)
47 q_next = argt->requestq.q_next;
51 atah = (
struct ac_ata_h *)argt->requestq.q_next;
55 argt->requestq.q_prev = 0;
56 argt->requestq.q_next = 0;
60 _next_ = (
struct ac_ata_h *)q_next->q_next;
61 _next_->a_chain.q_prev = q_next->q_prev;
62 argt->requestq.q_next = &_next_->a_chain;
69 tmout = atah->a_tmout;
74 acTimerAdd(&argt->timer, (acTimerDone)ata_timer_done, argt, tmout);
75 v10 = a_ops->ao_command(atah, 32, 78);
76 acTimerRemove(&argt->timer);
77 if ( v10 < 0 && a_ops->ao_error )
79 acTimerAdd(&argt->timer, (acTimerDone)ata_timer_done, argt, 0xF4240u);
80 v10 = a_ops->ao_error(atah, v10);
81 acTimerRemove(&argt->timer);
84 a_ops->ao_done(atah, v10);
85 CancelWakeupThread(0);
91 if ( thid != argt->thid )
96static int ata_intr(
const struct ata_softc *arg)
103 *((
volatile acUint16 *)0xB3000000) = 0;
110int ata_request(
struct ac_ata_h *atah,
int (*wakeup)(
int thid))
119 if ( (atah->a_flag & 0x10) != 0 )
122 if ( (Atac.active & unit) == 0 )
128 if ( Atac.thid == 0 )
134 if ( Atac.requestq.q_next )
140 Atac.requestq.q_prev = (
acQueueT)&Atac;
141 Atac.requestq.q_next = (
acQueueT)&Atac;
143 q_prev = Atac.requestq.q_prev;
144 atah->a_chain.q_next = (
acQueueT)&Atac;
145 atah->a_chain.q_prev = q_prev;
146 q_prev->q_next = &atah->a_chain;
147 Atac.requestq.q_prev = &atah->a_chain;
167static int ata_thread_init(
struct ata_softc *atac,
int priority)
172 param.attr = 0x2000000;
173 param.thread = ata_thread;
174 param.priority = priority;
175 param.stacksize = 0x800;
177 th = CreateThread(¶m);
179 StartThread(th, atac);
183int ata_probe(acAtaReg atareg)
190 while ( (*((
volatile acUint16 *)0xB6070000) & 0x80) != 0 )
192 *((
volatile acUint16 *)0xB6020000) = 4660;
193 *((
volatile acUint16 *)0xB6030000) = 18;
196 *((
volatile acUint16 *)0xB6160000) = 2;
197 *((
volatile acUint16 *)0xB6010000) = 0;
201 *((
volatile acUint16 *)0xB6060000) = 16 * (unit != 0);
202 *((
volatile acUint16 *)0xB6070000) = 0;
203 while (
count <= 1999999 )
206 if ( (*((
volatile acUint16 *)0xB6070000) & 0x80) == 0 )
218static int ata_module_optarg(
const char *str,
int default_value)
223 result = strtol(str, &next, 0);
225 return default_value;
229int acAtaModuleStart(
int argc,
char **argv)
243 if ( acAtaModuleStatus() != 0 )
247 cmdprio = Atac.cprio;
259 while ( index < argc )
267 delay = ata_module_optarg(opt + 2, delay);
269 else if ( v13 >= 101 )
274 prio = ata_module_optarg(opt_v11, prio);
282 cmdprio = ata_module_optarg(opt_v10, cmdprio);
289 if ( prio < cmdprio )
293 Atac.cprio = cmdprio;
295 Atac.requestq.q_prev = 0;
296 Atac.requestq.q_next = 0;
298 ChangeThreadPriority(0, 123);
299 index_v12 = ata_probe((acAtaReg)0xB6000000);
300 Atac.active = index_v12;
301 if ( index_v12 == 0 )
303 msg =
"probe device";
308 index_v12 = acIntrRegister(AC_INTR_NUM_ATA, (acIntrHandler)ata_intr, &Atac);
309 if ( index_v12 < 0 && index_v12 != -11 )
311 msg =
"register intr";
318 v18 = ata_thread_init(&Atac, prio);
322 acIntrRelease(AC_INTR_NUM_ATA);
329 if ( acIntrEnable(AC_INTR_NUM_ATA) < 0 )
340 for ( i = 1000;; i = 1000000 )
345 ret = DeleteThread(thid);
348 printf(
"acata:term_thread: DELETE ret=%d\n", ret);
351 acIntrRelease(AC_INTR_NUM_ATA);
362 printf(
"acata: %s: error %d\n", msg, index_v12);
370 if ( acAtaModuleStatus() == 0 )
381 for ( i = 1000;; i = 1000000 )
386 ret = DeleteThread(thid);
389 printf(
"acata:term_thread: DELETE ret=%d\n", ret);
392 acIntrDisable(AC_INTR_NUM_ATA);
393 acIntrRelease(AC_INTR_NUM_ATA);
398int acAtaModuleRestart(
int argc,
char **argv)
405int acAtaModuleStatus()
415 if ( !Atac.requestq.q_next )
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)
u32 count
start sector of fragmented bd/file