Skip to content

Commit 0d48a75

Browse files
authored
Merge pull request #453 from AKuHAK/UDMA
Set maximum supported UDMA mode, instead of hardcoded UDMA4
2 parents 5f536b8 + 56d68c9 commit 0d48a75

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

common/include/atahw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ enum _ata_identify_offsets {
166166
ATA_ID_SECTOTAL_LO = 60,
167167
ATA_ID_SECTOTAL_HI = 61,
168168
ATA_ID_COMMAND_SETS_SUPPORTED = 83,
169+
ATA_ID_UDMA_CONTROL = 88,
169170
ATA_ID_48BIT_SECTOTAL_LO = 100,
170171
ATA_ID_48BIT_SECTOTAL_MI = 101,
171172
ATA_ID_48BIT_SECTOTAL_HI = 102,

iop/dev9/atad/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ ATA_GAMESTAR_WORKAROUND ?= 1
2121
# Enable to enable support for the BDM interface.
2222
ATA_ENABLE_BDM ?= 0
2323

24+
# Enable to enable support for the BDM interface.
25+
ATA_ENABLE_MAXUDMA ?= 0
26+
2427
IOP_BIN ?= ps2atad.irx
2528

2629
IOP_INCS += -I$(PS2SDKSRC)/iop/dev9/dev9/include
@@ -47,6 +50,10 @@ IOP_CFLAGS += -DATA_ENABLE_BDM=1 -Wno-strict-aliasing
4750
IOP_INCS += -I$(PS2SDKSRC)/iop/fs/bdm/include
4851
endif
4952

53+
ifeq ($(ATA_ENABLE_MAXUDMA),1)
54+
IOP_CFLAGS += -DATA_ENABLE_MAXUDMA=1
55+
endif
56+
5057
include $(PS2SDKSRC)/Defs.make
5158
include $(PS2SDKSRC)/iop/Rules.bin.make
5259
include $(PS2SDKSRC)/iop/Rules.make

iop/dev9/atad/src/ps2atad.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ IRX_ID(MODNAME, 2, 7);
4646
#define M_PRINTF(format, args...) \
4747
printf(MODNAME ": " format, ##args)
4848

49-
#define U64_2XU32(val) ((u32*)val)[1], ((u32*)val)[0]
49+
#define U64_2XU32(val) ((u32 *)val)[1], ((u32 *)val)[0]
5050

5151
#define BANNER "ATA device driver %s - Copyright (c) 2003 Marcus R. Brown\n"
5252
#define VERSION "v1.2"
@@ -182,7 +182,7 @@ typedef struct _ata_cmd_state
182182
static ata_cmd_state_t atad_cmd_state;
183183

184184
#ifdef ATA_ENABLE_BDM
185-
#define NUM_DEVICES 2
185+
#define NUM_DEVICES 2
186186
#define ATA_BD_SECTOR_SIZE 512
187187
static struct block_device g_ata_bd[NUM_DEVICES];
188188
#endif
@@ -307,14 +307,14 @@ int _start(int argc, char *argv[])
307307
int i;
308308

309309
for (i = 0; i < NUM_DEVICES; ++i) {
310-
g_ata_bd[i].priv = (void *)&atad_devinfo[i];
311-
g_ata_bd[i].name = "ata";
312-
g_ata_bd[i].devNr = i;
313-
g_ata_bd[i].parNr = 0;
314-
g_ata_bd[i].parId = 0x00;
315-
g_ata_bd[i].sectorSize = 512;
310+
g_ata_bd[i].priv = (void *)&atad_devinfo[i];
311+
g_ata_bd[i].name = "ata";
312+
g_ata_bd[i].devNr = i;
313+
g_ata_bd[i].parNr = 0;
314+
g_ata_bd[i].parId = 0x00;
315+
g_ata_bd[i].sectorSize = 512;
316316
g_ata_bd[i].sectorOffset = 0;
317-
g_ata_bd[i].sectorCount = 0;
317+
g_ata_bd[i].sectorCount = 0;
318318

319319
g_ata_bd[i].read = ata_bd_read;
320320
g_ata_bd[i].write = ata_bd_write;
@@ -912,19 +912,19 @@ int ata_device_sector_io64(int device, void *buf, u64 lba, u32 nsectors, int dir
912912
len = (nsectors > 65536) ? 65536 : nsectors;
913913

914914
/* Combine bits 24-31 and bits 0-7 of lba into sector. */
915-
sector = ((lba >> 16) & 0xff00) | (lba & 0xff);
916-
lcyl = ((lba >> 24) & 0xff00) | ((lba >> 8) & 0xff);
917-
hcyl = ((lba >> 32) & 0xff00) | ((lba >> 16) & 0xff);
915+
sector = ((lba >> 16) & 0xff00) | (lba & 0xff);
916+
lcyl = ((lba >> 24) & 0xff00) | ((lba >> 8) & 0xff);
917+
hcyl = ((lba >> 32) & 0xff00) | ((lba >> 16) & 0xff);
918918

919919
/* In v1.04, LBA was enabled here. */
920920
select = (device << 4) & 0xffff;
921921
command = (dir == 1) ? ATA_C_WRITE_DMA_EXT : ATA_C_READ_DMA_EXT;
922922
} else {
923923
/* Setup for 28-bit LBA. */
924924
len = (nsectors > 256) ? 256 : nsectors;
925-
sector = lba & 0xff;
926-
lcyl = (lba >> 8) & 0xff;
927-
hcyl = (lba >> 16) & 0xff;
925+
sector = lba & 0xff;
926+
lcyl = (lba >> 8) & 0xff;
927+
hcyl = (lba >> 16) & 0xff;
928928

929929
/* In v1.04, LBA was enabled here. */
930930
select = ((device << 4) | ((lba >> 24) & 0xf)) & 0xffff;
@@ -1142,8 +1142,22 @@ static int ata_init_devices(ata_devinfo_t *devinfo)
11421142

11431143
devinfo[i].security_status = ata_param[ATA_ID_SECURITY_STATUS];
11441144

1145+
u8 maxUDMA = 4;
1146+
#ifdef ATA_ENABLE_MAXUDMA
1147+
maxUDMA = 6;
1148+
#endif
1149+
11451150
/* Ultra DMA mode 4. */
1146-
ata_device_set_transfer_mode(i, ATA_XFER_MODE_UDMA, 4);
1151+
u8 udmaMode = 4;
1152+
/* Check the highest UDMA mode supported */
1153+
for (int j = maxUDMA; j >= 0; j--) {
1154+
/* Check if the current UDMA mode is supported, store it and exit from the loop. */
1155+
if (((ata_param[ATA_ID_UDMA_CONTROL] & 0xFF) & (1 << j)) != 0) {
1156+
udmaMode = j;
1157+
break;
1158+
}
1159+
}
1160+
ata_device_set_transfer_mode(i, ATA_XFER_MODE_UDMA, udmaMode);
11471161
ata_device_smart_enable(i);
11481162
/* Set standby timer to 21min 15s. */
11491163
ata_device_idle(i, 0xff);
@@ -1330,7 +1344,7 @@ static int ata_bd_read(struct block_device *bd, u64 sector, void *buffer, u16 co
13301344

13311345
static int ata_bd_write(struct block_device *bd, u64 sector, const void *buffer, u16 count)
13321346
{
1333-
if (ata_device_sector_io64(bd->devNr, (void*)buffer, sector, count, ATA_DIR_WRITE) != 0) {
1347+
if (ata_device_sector_io64(bd->devNr, (void *)buffer, sector, count, ATA_DIR_WRITE) != 0) {
13341348
return -EIO;
13351349
}
13361350

0 commit comments

Comments
 (0)