Lines Matching refs:ide
67 IDE *ide; // IDE Controller
73 bool IDE_HasController(IDE *ide);
74 void IDE_Reset(IDE *ide);
75 void IDE_Identify(IDE *ide, int drive);
108 IDEWaitForBusy(IDE *ide, bool wait)
112 ASSERT(Spinlock_IsHeld(&ide->lock));
115 inb(ide->base + IDE_STATUS);
116 inb(ide->base + IDE_STATUS);
117 inb(ide->base + IDE_STATUS);
118 inb(ide->base + IDE_STATUS);
122 status = inb(ide->base + IDE_STATUS);
131 IDE_HasController(IDE *ide)
133 outb(ide->base + IDE_LBALOW, 0x41);
134 outb(ide->base + IDE_LBAMID, 0x4D);
136 if (inb(ide->base + IDE_LBALOW) != 0x41)
138 if (inb(ide->base + IDE_LBAMID) != 0x4D)
145 IDE_Reset(IDE *ide)
149 outb(ide->devctl, IDE_CONTROL_SRST);
150 outb(ide->devctl, 0);
152 status = IDEWaitForBusy(ide, true);
154 Log(ide, "Controller not ready!\n");
182 IDE_Identify(IDE *ide, int drive)
195 outb(ide->base + IDE_DRIVE, driveCode);
197 status = IDEWaitForBusy(ide, true);
199 Log(ide, "Error selecting drive %d\n", drive);
202 ide->lastDriveCode = driveCode;
204 outb(ide->base + IDE_SECTORCOUNT, 0x00);
205 outb(ide->base + IDE_LBALOW, 0x00);
206 outb(ide->base + IDE_LBAMID, 0x00);
207 outb(ide->base + IDE_LBAHIGH, 0x00);
208 outb(ide->base + IDE_COMMAND, IDE_CMD_IDENTIFY);
210 status = inb(ide->base + IDE_STATUS);
212 Log(ide, "Drive %d not present\n", drive);
220 status = inb(ide->base + IDE_STATUS);
224 Log(ide, "Error trying to identify drive %d\n", drive);
228 insw(ide->base, (void *)&ident, 256);
242 Log(ide, "Drive %d Model: %s Serial: %s\n", drive, model, serial);
243 Log(ide, "Drive %d %llu Sectors (%llu MBs)\n",
246 primaryDrives[drive].ide = &primary;
318 IDE *ide;
322 ide = idedrive->ide;
329 Spinlock_Lock(&ide->lock);
330 outb(ide->base + IDE_DRIVE, driveCode);
331 outb(ide->base + IDE_COMMAND, IDE_CMD_FLUSH);
333 IDEWaitForBusy(ide, false);
334 Spinlock_Unlock(&ide->lock);
345 IDE *ide = drive->ide;
347 DLOG(ide, "read %llx %llx\n", off, len);
358 Spinlock_Lock(&ide->lock);
359 if (driveCode != ide->lastDriveCode) {
360 outb(ide->base + IDE_DRIVE, driveCode);
363 status = IDEWaitForBusy(ide, true);
365 Spinlock_Unlock(&ide->lock);
366 Log(ide, "Error selecting drive %d\n", drive->drive);
369 ide->lastDriveCode = driveCode;
373 outb(ide->base + IDE_SECTORCOUNT, len >> 8);
374 outb(ide->base + IDE_LBALOW, off >> 24);
375 outb(ide->base + IDE_LBAMID, off >> 32);
376 outb(ide->base + IDE_LBAHIGH, off >> 40);
378 outb(ide->base + IDE_SECTORCOUNT, len);
379 outb(ide->base + IDE_LBALOW, off & 0xff);
380 outb(ide->base + IDE_LBAMID, (off >> 8) & 0xff);
381 outb(ide->base + IDE_LBAHIGH, (off >> 16) & 0xff);
384 outb(ide->base + IDE_COMMAND, IDE_CMD_READ_EXT);
386 outb(ide->base + IDE_COMMAND, IDE_CMD_READ);
388 status = IDEWaitForBusy(ide, false);
390 Spinlock_Unlock(&ide->lock);
391 Log(ide, "Error trying read from drive %d\n", drive->drive);
399 insw(ide->base + IDE_DATAPORT, b, 256);
401 status = IDEWaitForBusy(ide, true);
403 Spinlock_Unlock(&ide->lock);
404 Log(ide, "Error reading from drive %d\n", drive->drive);
408 Spinlock_Unlock(&ide->lock);
419 IDE *ide = drive->ide;
421 DLOG(ide, "read %llx %llx\n", off, len);
432 Spinlock_Lock(&ide->lock);
433 if (driveCode != ide->lastDriveCode) {
434 outb(ide->base + IDE_DRIVE, driveCode);
437 status = IDEWaitForBusy(ide, true);
439 Spinlock_Unlock(&ide->lock);
440 Log(ide, "Error selecting drive %d\n", drive->drive);
443 ide->lastDriveCode = driveCode;
447 outb(ide->base + IDE_SECTORCOUNT, len >> 8);
448 outb(ide->base + IDE_LBALOW, off >> 24);
449 outb(ide->base + IDE_LBAMID, off >> 32);
450 outb(ide->base + IDE_LBAHIGH, off >> 40);
452 outb(ide->base + IDE_SECTORCOUNT, len);
453 outb(ide->base + IDE_LBALOW, off & 0xff);
454 outb(ide->base + IDE_LBAMID, (off >> 8) & 0xff);
455 outb(ide->base + IDE_LBAHIGH, (off >> 16) & 0xff);
458 outb(ide->base + IDE_COMMAND, IDE_CMD_WRITE_EXT);
460 outb(ide->base + IDE_COMMAND, IDE_CMD_WRITE);
462 status = IDEWaitForBusy(ide, false);
464 Spinlock_Unlock(&ide->lock);
465 Log(ide, "Error trying read from drive %d\n", drive->drive);
473 outsw(ide->base + IDE_DATAPORT, b, 256);
475 status = IDEWaitForBusy(ide, true);
477 Spinlock_Unlock(&ide->lock);
478 Log(ide, "Error reading from drive %d\n", drive->drive);
482 Spinlock_Unlock(&ide->lock);