Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions common/include/atahw.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ typedef struct _ata_hwport
(ata_hwport_t *)ATA_AIF_HDD_BASE

/* r_error bits. */
#define ATA_ERR_MARK 0x01
#define ATA_ERR_TRACK0 0x02
#define ATA_ERR_ABORT 0x04
#define ATA_ERR_MCR 0x08
#define ATA_ERR_ID 0x10
#define ATA_ERR_MC 0x20
#define ATA_ERR_ECC 0x40
#define ATA_ERR_ICRC 0x80
#define ATA_ERR_MARK 0x01 // bit 0 [AMNF] Address mark not found.
#define ATA_ERR_TRACK0 0x02 // bit 1 [TKZNF] Track zero not found.
#define ATA_ERR_ABORT 0x04 // bit 2 [ABRT] Aborted command.
#define ATA_ERR_MCR 0x08 // bit 3 [MCR] Media change request.
#define ATA_ERR_ID 0x10 // bit 4 [IDNF] ID not found.
#define ATA_ERR_MC 0x20 // bit 5 [MC] Media changed.
#define ATA_ERR_ECC 0x40 // bit 6 [UNC] Uncorrectable data error.
#define ATA_ERR_ICRC 0x80 // bit 7 [BBK] Bad Block detected.

/* r_status bits. */
#define ATA_STAT_ERR 0x01
Expand All @@ -68,7 +68,10 @@ typedef struct _ata_hwport
#define ATA_STAT_BUSY 0x80

/* r_select bits. */
#define ATA_SEL_LBA 0x40
/// In CHS addressing, bits 0 to 3 of the head. In LBA addressing, bits 24 to 27 of the block number.
/// bits 5 and 7 are supposed to be always set
#define ATA_SEL_DRV 0x10 // bit 4 [DRV] Selects the drive number.
#define ATA_SEL_LBA 0x40 // bit 6 [LBA] Uses CHS addressing if clear or LBA addressing if set.

/** ATA command codes. */
enum ATA_C_CODES {
Expand Down
16 changes: 16 additions & 0 deletions iop/arcade/acata/src/acata_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
#include <acata.h>
#include <irx_imports.h>

#define ACATA_A_DATA 0xB6000000 // Read/Write PIO data bytes

#define ACATA_R_DATA *((acAtaReg)0xB6000000) // Read/Write PIO data bytes
#define ACATA_R_FEATURE *((acAtaReg)0xB6010000) // [W] Used to control command specific interface features.
#define ACATA_R_ERROR ACATA_R_FEATURE // [R] Used to retrieve any error generated by the last ATA command executed.
#define ACATA_R_NSECTOR *((acAtaReg)0xB6020000) // Number of sectors to read/write (0 is a special value).
#define ACATA_R_SECTOR *((acAtaReg)0xB6030000) // This is CHS / LBA28 / LBA48 specific.
#define ACATA_R_LCYL *((acAtaReg)0xB6040000) // Partial Disk Sector address.
#define ACATA_R_HCYL *((acAtaReg)0xB6050000) // Partial Disk Sector address.
#define ACATA_R_SELECT *((acAtaReg)0xB6060000) // Used to select a drive and/or head. Supports extra address/flag bits. [`ACATA_UNIT0`, `ACATA_UNIT1`]
#define ACATA_R_STATUS *((acAtaReg)0xB6070000) // [R] Used to read the current status.
#define ACATA_R_COMMAND ACATA_R_STATUS // [W] Used to send ATA commands to the device.
#define ACATA_R_STATUS_ALT *((acAtaReg)0xB6160000) // [R] A duplicate of the Status Register which does not affect interrupts.
#define ACATA_R_CONTROL ACATA_R_STATUS_ALT // [W] Used to reset the bus or enable/disable interrupts.


struct ata_softc
{
acQueueHeadData requestq;
Expand Down
24 changes: 12 additions & 12 deletions iop/arcade/acata/src/ata.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,30 +188,30 @@ int ata_probe(acAtaReg atareg)
int count;

(void)atareg;
while ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY) != 0 )
while ( (ACATA_R_STATUS & ATA_STAT_BUSY) != 0 )
;
*((volatile acUint16 *)0xB6020000) = 4660;
ACATA_R_NSECTOR = 4660;
// cppcheck-suppress knownConditionTrueFalse
if ( *((volatile acUint16 *)0xB6020000) != 52 )
if ( ACATA_R_NSECTOR != 52 )
return 0;
*((volatile acUint16 *)0xB6030000) = 18;
ACATA_R_SECTOR = 18;
// cppcheck-suppress knownConditionTrueFalse
if ( *((volatile acUint16 *)0xB6030000) != 18 )
if ( ACATA_R_SECTOR != 18 )
return 0;
active = 0;
unit = 0;
*((volatile acUint16 *)0xB6160000) = 2;
*((volatile acUint16 *)0xB6010000) = 0;
ACATA_R_CONTROL = 2;
ACATA_R_FEATURE = 0;
count = 0;
while ( unit < 2 )
{
*((volatile acUint16 *)0xB6060000) = 16 * (unit != 0);
*((volatile acUint16 *)0xB6070000) = 0;
*((volatile acUint16 *)0xB6070000) = 0;
ACATA_R_SELECT = 16 * (unit != 0);
ACATA_R_COMMAND = 0;
ACATA_R_COMMAND = 0;
while ( count <= 1999999 )
{
// cppcheck-suppress knownConditionTrueFalse
if ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY) == 0 )
if ( (ACATA_R_STATUS & ATA_STAT_BUSY) == 0 )
break;
++count;
}
Expand Down Expand Up @@ -304,7 +304,7 @@ int acAtaModuleStart(int argc, char **argv)
Atac.requestq.q_next = 0;
DelayThread(delay);
ChangeThreadPriority(0, 123);
index_v12 = ata_probe((acAtaReg)0xB6000000);
index_v12 = ata_probe((acAtaReg)ACATA_A_DATA);
Atac.active = index_v12;
if ( index_v12 == 0 )
{
Expand Down
64 changes: 32 additions & 32 deletions iop/arcade/acata/src/atacmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static int ata_dma_xfer(acDmaT dma, int intr, acDmaOp op)
if ( dmatmp->ad_state == 31 )
{
dmatmp->ad_result = dmatmp->ad_ata->ac_h.a_size;
return op(dma, (void *)0xB6000000, dmatmp->ad_ata->ac_h.a_buf, dmatmp->ad_ata->ac_h.a_size);
return op(dma, (void *)ACATA_A_DATA, dmatmp->ad_ata->ac_h.a_buf, dmatmp->ad_ata->ac_h.a_size);
}
thid = dmatmp->ad_thid;
dmatmp->ad_state = 3;
Expand Down Expand Up @@ -143,15 +143,15 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)
cmd = ata->ac_command;
count = 5;
flag_v8 = atah->a_flag;
*((volatile acUint16 *)0xB6060000) = flag_v8 & 0x10;
*((volatile acUint16 *)0xB6160000) = (flag_v8 & 2) ^ 2;
*((volatile acUint16 *)0xB6010000) = 0;
ACATA_R_SELECT = flag_v8 & 0x10;
ACATA_R_CONTROL = (flag_v8 & 2) ^ 2;
ACATA_R_FEATURE = 0;
while ( count >= 0 )
{
int data;

data = *cmd++;
*(acUint16 *)(((2 * ((data >> 8) & 8) + ((data >> 8) & 7)) << 16) + 0xB6000000) = data & 0xFF;
*(acUint16 *)(((2 * ((data >> 8) & 8) + ((data >> 8) & 7)) << 16) + ACATA_A_DATA) = data & 0xFF;
--count;
if ( ((data >> 8) & 0xF) == 7 )
{
Expand Down Expand Up @@ -183,7 +183,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)
int a_size;

a_size = atah->a_size;
while ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY) != 0 )
while ( (ACATA_R_STATUS & ATA_STAT_BUSY) != 0 )
;
while ( a_size > 0 )
{
Expand All @@ -199,7 +199,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)
a_size -= xlen;
xlen_v15 = (unsigned int)xlen >> 1;
xlen_v16 = xlen_v15 - 1;
while ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_DRQ) != 0 )
while ( (ACATA_R_STATUS & ATA_STAT_DRQ) != 0 )
{
int ret_v17;

Expand All @@ -209,27 +209,27 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)
ret_v17 = *a_buf;
a_buf++;
}
*((volatile acUint16 *)0xB6000000) = ret_v17;
ACATA_R_DATA = ret_v17;
--xlen_v16;
}
if ( (flag_v8 & 2) != 0 )
{
sr = *((volatile acUint16 *)0xB6160000);
sr = ACATA_R_STATUS_ALT;
ret_v20 = sr & 0xFF;
while ( (ret_v20 & 0x80) != 0 )
while ( (ret_v20 & ATA_STAT_BUSY) != 0 )
{
ret_v20 = -116;
if ( SleepThread() != 0 )
break;
ret_v20 = *((volatile acUint16 *)0xB6160000);
ret_v20 = ACATA_R_STATUS_ALT;
}
}
else
{
ret_v20 = *((volatile acUint16 *)0xB6070000);
ret_v20 = ACATA_R_STATUS;
while ( (ret_v20 & ATA_STAT_BUSY) != 0 )
{
sr = *((volatile acUint16 *)0xB6070000);
sr = ACATA_R_STATUS;
ret_v20 = sr & 0xFF;
}
}
Expand All @@ -256,22 +256,22 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)

if ( (flag_v8 & 2) != 0 )
{
sr_v25 = *((volatile acUint16 *)0xB6160000);
sr_v25 = ACATA_R_STATUS_ALT;
sr_v25 = sr_v25 & 0xFF;
while ( (sr_v25 & 0x80) != 0 )
{
sr_v25 = -116;
if ( SleepThread() )
break;
sr_v25 = *((volatile acUint16 *)0xB6160000);
sr_v25 = ACATA_R_STATUS_ALT;
}
}
else
{
sr_v25 = *((volatile acUint16 *)0xB6070000);
sr_v25 = ACATA_R_STATUS;
while ( (sr_v25 & ATA_STAT_BUSY) != 0 )
{
sr_v25 = *((volatile acUint16 *)0xB6070000);
sr_v25 = ACATA_R_STATUS;
sr_v25 = sr_v25 & 0xFF;
}
}
Expand All @@ -284,18 +284,18 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)
xlen_v28 = (unsigned int)xlen_v27 >> 1;
if ( (sr_v25 & 1) != 0 )
xlen_v28 = 0;
(void)(*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY);
(void)(ACATA_R_STATUS & ATA_STAT_BUSY);
xlen_v30 = xlen_v28 - 1;
while ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_DRQ) != 0 )
while ( (ACATA_R_STATUS & ATA_STAT_DRQ) != 0 )
{
if ( xlen_v30 >= 0 )
{
*buf_v23 = *((volatile acUint16 *)0xB6000000);
*buf_v23 = ACATA_R_DATA;
buf_v23++;
}
--xlen_v30;
}
ret_v29 = *((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY;
ret_v29 = ACATA_R_STATUS & ATA_STAT_BUSY;
if ( !ret_v29 )
break;
}
Expand All @@ -313,14 +313,14 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)
{
int v38;

v38 = *((volatile acUint16 *)0xB6160000) & 1;
v38 = ACATA_R_STATUS_ALT & ATA_STAT_ERR;
if ( v38 || state >= 511 )
{
printf(
"acata:A:dma_iowait: TIMEDOUT %04x:%02x:%02x\n",
state,
*((volatile acUint16 *)0xB6160000),
*((volatile acUint16 *)0xB6010000));
ACATA_R_STATUS_ALT,
ACATA_R_ERROR);
if ( state < 1023 )
acDmaCancel(&dma_data.ad_dma, -116);
ret = 0;
Expand All @@ -329,7 +329,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)
break;
}
state = dma_data.ad_state;
if ( (*((volatile acUint16 *)0xB6160000) & 0x80) == 0 && (int)dma_data.ad_state >= 64 )
if ( (ACATA_R_STATUS_ALT & ATA_STAT_BUSY) == 0 && (int)dma_data.ad_state >= 64 )
{
ret = dma_data.ad_result;
break;
Expand All @@ -347,7 +347,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)
ret = 0;
if ( v16 )
{
while ( (*((volatile acUint16 *)0xB6160000) & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY )
while ( (ACATA_R_STATUS_ALT & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY )
{
if ( SleepThread() )
{
Expand All @@ -361,7 +361,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)
int tmout;

tmout = 99999;
while ( (*((volatile acUint16 *)0xB6070000) & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY )
while ( (ACATA_R_STATUS & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY )
{
if ( tmout < 0 )
{
Expand All @@ -380,9 +380,9 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)
{
return ret;
}
sr_v34 = *((volatile acUint16 *)0xB6070000);
if ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_ERR) != 0 )
return -((sr_v34 << 8) + *((volatile acUint16 *)0xB6010000));
sr_v34 = ACATA_R_STATUS;
if ( (ACATA_R_STATUS & ATA_STAT_ERR) != 0 )
return -((sr_v34 << 8) + ACATA_R_ERROR);
if ( atah->a_state < 0x1FFu )
{
atah->a_state = 127;
Expand All @@ -395,15 +395,15 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri)
cmd_v36 = ata->ac_command;
if ( ret_v35 < 0 )
{
return -((sr_v34 << 8) + *((volatile acUint16 *)0xB6010000));
return -((sr_v34 << 8) + ACATA_R_ERROR);
}
for ( rest_v37 = 6; rest_v37 > 0; --rest_v37 )
{
if ( (((int)*cmd_v36 >> 12) & 0xF) == 0 )
break;
*cmd_v36 =
((((int)*cmd_v36 >> 12) & 0xF) << 12)
| ((*(acUint16 *)(((2 * (((int)*cmd_v36 >> 12) & 8) + (((int)*cmd_v36 >> 12) & 7)) << 16) + 0xB6000000)) & 0xFF);
| ((*(acUint16 *)(((2 * (((int)*cmd_v36 >> 12) & 8) + (((int)*cmd_v36 >> 12) & 7)) << 16) + ACATA_A_DATA)) & 0xFF);
++cmd_v36;
}
return 6 - rest_v37;
Expand Down
Loading
Loading