}
static void
-execute_command (struct disk *d, uint8_t command)
+issue_command (struct disk *d, uint8_t command)
{
struct channel *c = d->channel;
c->expecting_interrupt = true;
outb (reg_command (c), command);
intr_enable ();
-
- /* Wait for the command to complete. */
- sema_down (&c->completion_wait);
}
static bool
int last;
int i;
- for (last = word_cnt * 2 - 1; last >= 0; last--)
- if (string[last ^ 1] != ' ')
- break;
+ for (last = word_cnt * 2 - 1; last >= 0; last--)
+ {
+ int c = string[last ^ 1];
+ if (c != '\0' && !isspace (c))
+ break;
+ }
for (i = 0; i <= last; i++)
printk ("%c", string[i ^ 1]);
ASSERT (d->is_ata);
select_device_wait (d);
- execute_command (d, CMD_IDENTIFY);
+ issue_command (d, CMD_IDENTIFY);
+ sema_down (&d->channel->completion_wait);
wait_while_busy (d);
if (!input_sector (d->channel, id))
printk ("%"PRDSNu" kB", d->capacity / (1024 / DISK_SECTOR_SIZE));
else
printk ("%"PRDSNu" byte", d->capacity * DISK_SECTOR_SIZE);
- printk (") disk \"");
+ printk (") disk, model \"");
printk_ata_string ((char *) &id[27], 20);
- printk (" ");
+ printk ("\", serial \"");
printk_ata_string ((char *) &id[10], 10);
printk ("\"\n");
}
lock_acquire (&d->channel->lock);
select_sector (d, sec_no);
- execute_command (d, CMD_READ_SECTOR_RETRY);
+ issue_command (d, CMD_READ_SECTOR_RETRY);
+ sema_down (&d->channel->completion_wait);
wait_while_busy (d);
if (!input_sector (d->channel, buffer))
panic ("%s: disk read failed, sector=%"PRDSNu, d->name, sec_no);
+ lock_release (&d->channel->lock);
}
void
lock_acquire (&d->channel->lock);
select_sector (d, sec_no);
- execute_command (d, CMD_WRITE_SECTOR_RETRY);
+ issue_command (d, CMD_WRITE_SECTOR_RETRY);
wait_while_busy (d);
if (!output_sector (d->channel, buffer))
panic ("%s: disk write failed, sector=%"PRDSNu, d->name, sec_no);
+ sema_down (&d->channel->completion_wait);
lock_release (&d->channel->lock);
}