X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdevices%2Fdisk.c;h=5320d2e48f602c8eb1b5a36f9899b789263fb362;hb=9869570326bb4e6d39fb41912a9076d53a82ad2d;hp=baf120864399f11a8c33ae27f37a41992b413cab;hpb=838c30d0075a3ee0413ba4909944b37f4970a10d;p=pintos-anon diff --git a/src/devices/disk.c b/src/devices/disk.c index baf1208..5320d2e 100644 --- a/src/devices/disk.c +++ b/src/devices/disk.c @@ -8,6 +8,9 @@ #include "threads/interrupt.h" #include "threads/synch.h" +/* The code in this file is an interface to an ATA (IDE) + controller. It attempts to comply to [ATA-3]. */ + /* ATA command block port addresses. */ #define reg_data(CHANNEL) ((CHANNEL)->reg_base + 0) /* Data. */ #define reg_error(CHANNEL) ((CHANNEL)->reg_base + 1) /* Error. */ @@ -106,7 +109,7 @@ disk_init (void) int dev_no; /* Initialize channel. */ - snprintf (c->name, sizeof c->name, "hd%zd", chan_no); + snprintf (c->name, sizeof c->name, "hd%zu", chan_no); switch (chan_no) { case 0: @@ -201,6 +204,15 @@ disk_size (struct disk *d) return d->capacity; } +/* Returns a human-readable name for disk D. */ +const char * +disk_name (struct disk *d) +{ + ASSERT (d != NULL); + + return d->name; +} + /* Reads sector SEC_NO from disk D into BUFFER, which must have room for DISK_SECTOR_SIZE bytes. */ void @@ -282,12 +294,12 @@ reset_channel (struct channel *c) /* Issue soft reset sequence, which selects device 0 as a side effect. Also enable interrupts. */ outb (reg_ctl (c), 0); - timer_sleep (timer_us2ticks (10)); + timer_usleep (10); outb (reg_ctl (c), CTL_SRST); - timer_sleep (timer_us2ticks (10)); + timer_usleep (10); outb (reg_ctl (c), 0); - timer_sleep (timer_ms2ticks (150)); + timer_msleep (150); /* Wait for device 0 to clear BSY. */ if (present[0]) @@ -306,7 +318,7 @@ reset_channel (struct channel *c) { if (inb (reg_nsect (c)) == 1 && inb (reg_lbal (c)) == 1) break; - timer_sleep (timer_ms2ticks (10)); + timer_msleep (10); } wait_while_busy (&c->devices[1]); } @@ -370,15 +382,7 @@ identify_ata_device (struct disk *d) /* Print identification message. */ printf ("%s: detected %'"PRDSNu" sector (", d->name, d->capacity); - if (d->capacity > 1024 / DISK_SECTOR_SIZE * 1024 * 1024) - printf ("%"PRDSNu" GB", - d->capacity / (1024 / DISK_SECTOR_SIZE * 1024 * 1024)); - else if (d->capacity > 1024 / DISK_SECTOR_SIZE * 1024) - printf ("%"PRDSNu" MB", d->capacity / (1024 / DISK_SECTOR_SIZE * 1024)); - else if (d->capacity > 1024 / DISK_SECTOR_SIZE) - printf ("%"PRDSNu" kB", d->capacity / (1024 / DISK_SECTOR_SIZE)); - else - printf ("%"PRDSNu" byte", d->capacity * DISK_SECTOR_SIZE); + print_human_readable_size ((uint64_t) d->capacity * DISK_SECTOR_SIZE); printf (") disk, model \""); print_ata_string ((char *) &id[27], 40); printf ("\", serial \""); @@ -472,7 +476,7 @@ wait_until_idle (const struct disk *d) { if ((inb (reg_status (d->channel)) & (STA_BSY | STA_DRQ)) == 0) return; - timer_sleep (timer_us2ticks (10)); + timer_usleep (10); } printf ("%s: idle timeout\n", d->name); @@ -498,7 +502,7 @@ wait_while_busy (const struct disk *d) printf ("ok\n"); return (inb (reg_alt_status (c)) & STA_DRQ) != 0; } - timer_sleep (timer_ms2ticks (10)); + timer_msleep (10); } printf ("failed\n"); @@ -515,7 +519,7 @@ select_device (const struct disk *d) dev |= DEV_DEV; outb (reg_device (c), dev); inb (reg_alt_status (c)); - timer_sleep (timer_ns2ticks (400)); + timer_nsleep (400); } /* Select disk D in its channel, as select_device(), but wait for