|
3 | 3 | #include <util/console.h> |
4 | 4 | #include <interrupt/irq.h> |
5 | 5 |
|
| 6 | +/* Detected drive id recorded after successful ata_init() */ |
| 7 | +static int g_ata_detected_drive = -1; |
| 8 | + |
| 9 | +int ata_get_detected_drive(void) { |
| 10 | + return g_ata_detected_drive; |
| 11 | +} |
| 12 | + |
6 | 13 | /** |
7 | 14 | * @brief ATAデバイスの準備完了を待つ |
8 | 15 | */ |
@@ -81,11 +88,12 @@ int ata_init(void) { |
81 | 88 | const struct { |
82 | 89 | uint16_t base; |
83 | 90 | uint8_t drive_sel; |
| 91 | + uint8_t drive_id; /* drive id used by ata_read_sectors */ |
84 | 92 | const char *name; |
85 | 93 | } drives[] = { |
86 | | - { ATA_PRIMARY_DATA, ATA_SLAVE, "Primary Slave (hdb)" }, |
87 | | - { ATA_SECONDARY_DATA, ATA_MASTER, "Secondary Master (hdc)" }, |
88 | | - { ATA_PRIMARY_DATA, ATA_MASTER, "Primary Master (hda)" }, |
| 94 | + { ATA_PRIMARY_DATA, ATA_SLAVE, 1, "Primary Slave (hdb)" }, |
| 95 | + { ATA_SECONDARY_DATA, ATA_MASTER, 2, "Secondary Master (hdc)" }, |
| 96 | + { ATA_PRIMARY_DATA, ATA_MASTER, 0, "Primary Master (hda)" }, |
89 | 97 | }; |
90 | 98 |
|
91 | 99 | for (int i = 0; i < 3; i++) { |
@@ -168,11 +176,21 @@ int ata_init(void) { |
168 | 176 | printk("ATA: reading IDENTIFY data from base 0x%x\n", |
169 | 177 | drives[i].base); |
170 | 178 | #endif |
| 179 | +#ifdef INIT_MSG |
| 180 | + for (int j = 0; j < 256; j++) { |
| 181 | + (void)inw(drives[i].base); |
| 182 | + } |
| 183 | +#else |
171 | 184 | for (int j = 0; j < 256; j++) { |
172 | 185 | (void)inw(drives[i].base); |
173 | 186 | } |
| 187 | +#endif |
| 188 | +#ifdef INIT_MSG |
| 189 | +#endif |
| 190 | + g_ata_detected_drive = drives[i].drive_id; |
174 | 191 | #ifdef INIT_MSG |
175 | | - printk("ATA: %s detected successfully!\n", drives[i].name); |
| 192 | + printk("ATA: %s detected successfully! (drive=%u)\n", |
| 193 | + drives[i].name, g_ata_detected_drive); |
176 | 194 | #endif |
177 | 195 | return 0; |
178 | 196 | } |
|
0 commit comments