-
Notifications
You must be signed in to change notification settings - Fork 0
Upstream #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upstream #39
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,47 @@ static void ata_shutdown_cb(void); | |
|
|
||
| int ata_device_sector_io_internal(int device, void *buf, u64 lba, u32 nsectors, int dir); | ||
|
|
||
| /* Wait until the ATA device becomes basically ready for commands. | ||
| BUSY must be clear (spin-up / firmware init done). | ||
| DRDY is validated later by ata_wait_for_ready() according to ATA spec. | ||
| */ | ||
| static int ata_wait_for_busy_clear(int timeout) | ||
| { | ||
| USE_ATA_REGS; | ||
|
|
||
| for (int waited = 0; waited < timeout; waited++) { | ||
| if (!(ata_hwport->r_status & ATA_STAT_BUSY)) | ||
| return 0; | ||
|
|
||
| DelayThread(1000); | ||
| } | ||
|
|
||
| M_PRINTF("ata_wait_for_busy_clear TIMEOUT after %d ms\n", timeout); | ||
| return ATA_RES_ERR_TIMEOUT; | ||
| } | ||
|
|
||
| static int ata_wait_for_ready(int timeout) | ||
| { | ||
| USE_ATA_REGS; | ||
|
|
||
| for (int waited = 0; waited < timeout; waited++) { | ||
| u8 status = ata_hwport->r_status; | ||
|
|
||
| if (!(status & ATA_STAT_BUSY) && (status & ATA_STAT_READY)) | ||
| return 0; | ||
|
|
||
| if (status & ATA_STAT_ERR) { | ||
| M_PRINTF("ata_wait_for_ready ERR: status=0x%02x err=0x%02x\n", status, sceAtaGetError()); | ||
| return ATA_RES_ERR_IO; | ||
| } | ||
|
|
||
| DelayThread(1000); | ||
| } | ||
|
Comment on lines
+143
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block has two issues:
{
USE_ATA_REGS;
int waited;
u8 status;
for (waited = 0; waited < timeout; waited++) {
status = ata_hwport->r_status;
if (!(status & ATA_STAT_BUSY)) {
if (status & ATA_STAT_READY)
return 0;
if (status & ATA_STAT_ERR) {
M_PRINTF("ata_wait_for_ready ERR: status=0x%02x err=0x%02x\n", status, sceAtaGetError());
return ATA_RES_ERR_IO;
}
}
DelayThread(1000);
} |
||
|
|
||
| M_PRINTF("ata_wait_for_ready TIMEOUT after %d ms\n", timeout); | ||
| return ATA_RES_ERR_TIMEOUT; | ||
| } | ||
|
|
||
| /* In v1.04, DMA was enabled in ata_set_dir() instead. */ | ||
| static void ata_pre_dma_cb(int bcr, int dir) | ||
| { | ||
|
|
@@ -205,6 +246,14 @@ int atad_start(void) | |
| bdm_connect_bd(&g_ata_bd); | ||
| #endif | ||
|
|
||
| res = ata_wait_for_busy_clear(30000); | ||
| if (res < 0) | ||
| goto out; | ||
|
Comment on lines
+250
to
+251
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error path is critical. If |
||
|
|
||
| res = ata_wait_for_ready(5000); | ||
| if (res < 0) | ||
| goto out; | ||
|
|
||
| res = 0; | ||
| M_PRINTF("Driver loaded.\n"); | ||
| out: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
waitedis declared inside theforloop, which is a C99 feature. To maintain consistency with the C89 style used throughout the rest of this file, please move the declaration to the top of the function.