PCI-IDE driver fallback to polling for PCI-native controllers
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m55s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m55s
This commit is contained in:
@@ -91,19 +91,16 @@ static void ide_irq (void* arg, void* regs, bool user, struct reschedule_ctx* rc
|
||||
uint64_t fd, fp;
|
||||
|
||||
struct idedrv* idedrv = arg;
|
||||
DEBUG ("1\n");
|
||||
|
||||
spin_lock (&idedrv->device->lock, &fd);
|
||||
|
||||
struct idedrv_request* req = idedrv->current_req;
|
||||
DEBUG ("2\n");
|
||||
|
||||
if (req == NULL) {
|
||||
(void)inb (idedrv->io + IDE_REG_STATUS);
|
||||
spin_unlock (&idedrv->device->lock, fd);
|
||||
return;
|
||||
}
|
||||
DEBUG ("3\n");
|
||||
|
||||
uint8_t status = inb (idedrv->io + IDE_REG_STATUS);
|
||||
|
||||
@@ -113,7 +110,6 @@ static void ide_irq (void* arg, void* regs, bool user, struct reschedule_ctx* rc
|
||||
spin_unlock (&idedrv->device->lock, fd);
|
||||
return;
|
||||
}
|
||||
DEBUG ("4\n");
|
||||
|
||||
if ((status & IDE_DRQ) && (req->sector_done_count < req->sector_count)) {
|
||||
uint16_t* p = req->buffer + (req->sector_done_count * (idedrv->sector_size / 2));
|
||||
@@ -124,17 +120,14 @@ static void ide_irq (void* arg, void* regs, bool user, struct reschedule_ctx* rc
|
||||
outsw (idedrv->io + IDE_REG_DATA, p, idedrv->sector_size / 2);
|
||||
|
||||
req->sector_done_count++;
|
||||
DEBUG ("4\n");
|
||||
}
|
||||
|
||||
if ((req->sector_done_count >= req->sector_count)) {
|
||||
atomic_store (&req->done, 1);
|
||||
idedrv->current_req = NULL;
|
||||
}
|
||||
DEBUG ("6\n");
|
||||
|
||||
spin_unlock (&idedrv->device->lock, fd);
|
||||
DEBUG ("7\n");
|
||||
}
|
||||
|
||||
void ide_probe (uint16_t io, uint16_t ctrl, uint8_t devno, struct ide_probe* probe) {
|
||||
@@ -164,7 +157,7 @@ void ide_probe (uint16_t io, uint16_t ctrl, uint8_t devno, struct ide_probe* pro
|
||||
if (status == 0)
|
||||
return;
|
||||
|
||||
if (!ide_wait (io, 100000, true, true)) {
|
||||
if (!ide_wait (io, 90000000, true, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -172,12 +165,10 @@ void ide_probe (uint16_t io, uint16_t ctrl, uint8_t devno, struct ide_probe* pro
|
||||
|
||||
probe->flags |= IDE_PROBE_AVAIL;
|
||||
|
||||
if ((identify_buffer[106] & 0xC000) == 0x4000) {
|
||||
if (identify_buffer[106] & (1 << 12)) {
|
||||
uint32_t words_per_sector =
|
||||
(uint32_t)identify_buffer[117] | ((uint32_t)identify_buffer[118] << 16);
|
||||
probe->sector_size = (size_t)words_per_sector * 2;
|
||||
}
|
||||
if ((identify_buffer[106] & 0xC000) == 0x4000 && identify_buffer[106] & (1 << 12)) {
|
||||
uint32_t words_per_sector =
|
||||
(uint32_t)identify_buffer[117] | ((uint32_t)identify_buffer[118] << 16);
|
||||
probe->sector_size = (size_t)words_per_sector * 2;
|
||||
}
|
||||
|
||||
if ((identify_buffer[83] & (1 << 10)) != 0)
|
||||
@@ -258,10 +249,12 @@ bool idedrv_init (struct device* device, void* arg, struct proc* proc,
|
||||
idedrv->devno = init->devno;
|
||||
idedrv->irq = init->irq;
|
||||
idedrv->current_req = NULL;
|
||||
idedrv->irqs_support = init->irqs_support;
|
||||
|
||||
device->udata = idedrv;
|
||||
|
||||
irq_attach (&ide_irq, idedrv, idedrv->irq);
|
||||
if (idedrv->irqs_support)
|
||||
irq_attach (&ide_irq, idedrv, idedrv->irq);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -274,7 +267,9 @@ void idedrv_fini (struct device* device, struct proc* proc, struct reschedule_ct
|
||||
idedrv->current_req = NULL;
|
||||
}
|
||||
|
||||
irq_detach (idedrv->irq);
|
||||
if (idedrv->irqs_support)
|
||||
irq_detach (idedrv->irq);
|
||||
|
||||
free (idedrv);
|
||||
}
|
||||
|
||||
@@ -291,46 +286,53 @@ int idedrv_read (struct device* device, struct proc* proc, struct reschedule_ctx
|
||||
|
||||
struct idedrv* idedrv = device->udata;
|
||||
|
||||
DEBUG ("1\n");
|
||||
|
||||
if (sector + sector_count > idedrv->sector_count)
|
||||
return -ST_OOB_ERROR;
|
||||
|
||||
if (!ide_wait (idedrv->io, 100000, false, false))
|
||||
return -ST_XDRV_READ_ERROR;
|
||||
|
||||
struct idedrv_request* req = malloc (sizeof (*req));
|
||||
if (idedrv->irqs_support) {
|
||||
struct idedrv_request* req = malloc (sizeof (*req));
|
||||
|
||||
if (req == NULL)
|
||||
return -ST_OOM_ERROR;
|
||||
if (req == NULL)
|
||||
return -ST_OOM_ERROR;
|
||||
|
||||
memset (req, 0, sizeof (*req));
|
||||
req->buffer = buffer;
|
||||
req->sector_count = sector_count;
|
||||
req->sector_done_count = 0;
|
||||
req->type = IDE_READ;
|
||||
DEBUG ("2\n");
|
||||
memset (req, 0, sizeof (*req));
|
||||
req->buffer = buffer;
|
||||
req->sector_count = sector_count;
|
||||
req->sector_done_count = 0;
|
||||
req->type = IDE_READ;
|
||||
|
||||
idedrv->current_req = req;
|
||||
idedrv->current_req = req;
|
||||
|
||||
ide_prepare (idedrv, sector, sector_count, true);
|
||||
DEBUG ("3\n");
|
||||
ide_prepare (idedrv, sector, sector_count, true);
|
||||
|
||||
DEBUG ("4\n");
|
||||
uint8_t cmd = idedrv->lba48 ? IDE_CMD_READ48 : IDE_CMD_READ28;
|
||||
outb (idedrv->io + IDE_REG_CMD, cmd);
|
||||
|
||||
uint8_t cmd = idedrv->lba48 ? IDE_CMD_READ48 : IDE_CMD_READ28;
|
||||
outb (idedrv->io + IDE_REG_CMD, cmd);
|
||||
DEBUG ("5\n");
|
||||
spin_unlock (&device->lock, *lockflags);
|
||||
|
||||
spin_unlock (&device->lock, *lockflags);
|
||||
while (!atomic_load (&req->done))
|
||||
spin_lock_relax ();
|
||||
|
||||
while (!atomic_load (&req->done))
|
||||
spin_lock_relax ();
|
||||
spin_lock (&device->lock, lockflags);
|
||||
|
||||
spin_lock (&device->lock, lockflags);
|
||||
DEBUG ("6\n");
|
||||
free (req);
|
||||
} else {
|
||||
ide_prepare (idedrv, sector, sector_count, false);
|
||||
|
||||
free (req);
|
||||
uint8_t cmd = idedrv->lba48 ? IDE_CMD_READ48 : IDE_CMD_READ28;
|
||||
outb (idedrv->io + IDE_REG_CMD, cmd);
|
||||
|
||||
for (uint16_t s = 0; s < sector_count; s++) {
|
||||
if (!ide_wait (idedrv->io, 100000, true, true))
|
||||
return -ST_XDRV_READ_ERROR;
|
||||
|
||||
insw (idedrv->io + IDE_REG_DATA, buffer + (s * (idedrv->sector_size / 2)),
|
||||
idedrv->sector_size / 2);
|
||||
}
|
||||
}
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
@@ -355,43 +357,58 @@ int idedrv_write (struct device* device, struct proc* proc, struct reschedule_ct
|
||||
if (!ide_wait (idedrv->io, 100000, false, false))
|
||||
return -ST_XDRV_WRITE_ERROR;
|
||||
|
||||
struct idedrv_request* req = malloc (sizeof (*req));
|
||||
if (idedrv->irqs_support) {
|
||||
struct idedrv_request* req = malloc (sizeof (*req));
|
||||
|
||||
if (req == NULL)
|
||||
return -ST_OOM_ERROR;
|
||||
if (req == NULL)
|
||||
return -ST_OOM_ERROR;
|
||||
|
||||
memset (req, 0, sizeof (*req));
|
||||
req->buffer = buffer;
|
||||
req->sector_count = sector_count;
|
||||
req->sector_done_count = 0;
|
||||
req->type = IDE_WRITE;
|
||||
memset (req, 0, sizeof (*req));
|
||||
req->buffer = buffer;
|
||||
req->sector_count = sector_count;
|
||||
req->sector_done_count = 0;
|
||||
req->type = IDE_WRITE;
|
||||
|
||||
idedrv->current_req = req;
|
||||
idedrv->current_req = req;
|
||||
|
||||
ide_prepare (idedrv, sector, sector_count, true);
|
||||
ide_prepare (idedrv, sector, sector_count, true);
|
||||
|
||||
uint8_t cmd = idedrv->lba48 ? IDE_CMD_WRITE48 : IDE_CMD_WRITE28;
|
||||
outb (idedrv->io + IDE_REG_CMD, cmd);
|
||||
uint8_t cmd = idedrv->lba48 ? IDE_CMD_WRITE48 : IDE_CMD_WRITE28;
|
||||
outb (idedrv->io + IDE_REG_CMD, cmd);
|
||||
|
||||
if (!ide_wait (idedrv->io, 100000, true, true)) {
|
||||
idedrv->current_req = NULL;
|
||||
free (req);
|
||||
return -ST_XDRV_WRITE_ERROR;
|
||||
}
|
||||
|
||||
outsw (idedrv->io + IDE_REG_DATA, buffer, idedrv->sector_size / 2);
|
||||
|
||||
req->sector_done_count = 1;
|
||||
|
||||
spin_unlock (&device->lock, *lockflags);
|
||||
|
||||
while (!atomic_load (&req->done))
|
||||
spin_lock_relax ();
|
||||
|
||||
spin_lock (&device->lock, lockflags);
|
||||
|
||||
if (!ide_wait (idedrv->io, 100000, true, true)) {
|
||||
idedrv->current_req = NULL;
|
||||
free (req);
|
||||
return -ST_XDRV_WRITE_ERROR;
|
||||
} else {
|
||||
ide_prepare (idedrv, sector, sector_count, false);
|
||||
|
||||
uint8_t cmd = idedrv->lba48 ? IDE_CMD_WRITE48 : IDE_CMD_WRITE28;
|
||||
outb (idedrv->io + IDE_REG_CMD, cmd);
|
||||
|
||||
for (uint16_t s = 0; s < sector_count; s++) {
|
||||
if (!ide_wait (idedrv->io, 100000, true, true))
|
||||
return -ST_XDRV_WRITE_ERROR;
|
||||
|
||||
outsw (idedrv->io + IDE_REG_DATA, buffer + (s * (idedrv->sector_size / 2)),
|
||||
idedrv->sector_size / 2);
|
||||
}
|
||||
}
|
||||
|
||||
outsw (idedrv->io + IDE_REG_DATA, buffer, idedrv->sector_size / 2);
|
||||
|
||||
req->sector_done_count = 1;
|
||||
|
||||
spin_unlock (&device->lock, *lockflags);
|
||||
|
||||
while (!atomic_load (&req->done))
|
||||
spin_lock_relax ();
|
||||
|
||||
spin_lock (&device->lock, lockflags);
|
||||
|
||||
free (req);
|
||||
|
||||
uint8_t ctrl = inb (idedrv->ctrl);
|
||||
ctrl |= 0x02;
|
||||
outb (idedrv->ctrl, ctrl);
|
||||
|
||||
Reference in New Issue
Block a user