idedrv Remove unlocking while waiting for interrupt
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 1m29s
Build documentation / build-and-deploy (push) Successful in 38s

This commit is contained in:
2026-04-26 23:13:44 +02:00
parent c191ac0a50
commit e0730c378c

View File

@@ -19,6 +19,7 @@
#include <proc/reschedule.h> #include <proc/reschedule.h>
#include <status.h> #include <status.h>
#include <sys/debug.h> #include <sys/debug.h>
#include <sys/intr.h>
#define IDE_REG_DATA 0x00 #define IDE_REG_DATA 0x00
#define IDE_REG_ERROR 0x01 #define IDE_REG_ERROR 0x01
@@ -107,17 +108,12 @@ static void ide_delay(uint16_t ctrl) {
static void ide_irq(void* arg, void* regs, bool user, struct reschedule_ctx* rctx) { static void ide_irq(void* arg, void* regs, bool user, struct reschedule_ctx* rctx) {
(void)user, (void)regs, (void)rctx; (void)user, (void)regs, (void)rctx;
uint64_t fd;
struct idedrv* idedrv = arg; struct idedrv* idedrv = arg;
spin_lock(&idedrv->device->lock, &fd);
struct idedrv_request* req = idedrv->current_req; struct idedrv_request* req = idedrv->current_req;
if (req == NULL) { if (req == NULL) {
(void)inb(idedrv->io + IDE_REG_STATUS); (void)inb(idedrv->io + IDE_REG_STATUS);
spin_unlock(&idedrv->device->lock, fd);
return; return;
} }
@@ -126,7 +122,6 @@ static void ide_irq(void* arg, void* regs, bool user, struct reschedule_ctx* rct
if ((status & (IDE_ERR | IDE_DF))) { if ((status & (IDE_ERR | IDE_DF))) {
atomic_store(&req->done, 1); atomic_store(&req->done, 1);
idedrv->current_req = NULL; idedrv->current_req = NULL;
spin_unlock(&idedrv->device->lock, fd);
return; return;
} }
@@ -145,8 +140,6 @@ static void ide_irq(void* arg, void* regs, bool user, struct reschedule_ctx* rct
atomic_store(&req->done, 1); atomic_store(&req->done, 1);
idedrv->current_req = NULL; idedrv->current_req = NULL;
} }
spin_unlock(&idedrv->device->lock, fd);
} }
void ide_probe(uint16_t io, uint16_t ctrl, uint8_t devno, struct ide_probe* probe) { void ide_probe(uint16_t io, uint16_t ctrl, uint8_t devno, struct ide_probe* probe) {
@@ -326,7 +319,7 @@ DEFINE_DEVICE_FINI(idedrv_fini) {
} }
static int idedrv_do_read_irqs(struct idedrv* idedrv, size_t sector, size_t sector_count, static int idedrv_do_read_irqs(struct idedrv* idedrv, size_t sector, size_t sector_count,
void* buffer, uint64_t* lockflags) { void* buffer) {
struct idedrv_request* req = malloc(sizeof(*req)); struct idedrv_request* req = malloc(sizeof(*req));
if (req == NULL) if (req == NULL)
@@ -345,12 +338,12 @@ static int idedrv_do_read_irqs(struct idedrv* idedrv, size_t sector, size_t sect
uint8_t cmd = idedrv->lba48 ? IDE_CMD_READ48 : IDE_CMD_READ28; uint8_t cmd = idedrv->lba48 ? IDE_CMD_READ48 : IDE_CMD_READ28;
outb(idedrv->io + IDE_REG_CMD, cmd); outb(idedrv->io + IDE_REG_CMD, cmd);
spin_unlock(&idedrv->device->lock, *lockflags); intr_enable();
while (!atomic_load(&req->done)) while (!atomic_load(&req->done))
spin_lock_relax(); spin_lock_relax();
spin_lock(&idedrv->device->lock, lockflags); intr_disable();
free(req); free(req);
@@ -454,13 +447,13 @@ DEFINE_DEVICE_OP(idedrv_read) {
return -ST_XDRV_READ_ERROR; return -ST_XDRV_READ_ERROR;
if (idedrv->irqs_support) if (idedrv->irqs_support)
return idedrv_do_read_irqs(idedrv, sector, sector_count, buffer, lockflags); return idedrv_do_read_irqs(idedrv, sector, sector_count, buffer);
else else
return idedrv_do_read_no_irqs(idedrv, sector, sector_count, buffer); return idedrv_do_read_no_irqs(idedrv, sector, sector_count, buffer);
} }
static int idedrv_do_write_irqs(struct idedrv* idedrv, size_t sector, size_t sector_count, static int idedrv_do_write_irqs(struct idedrv* idedrv, size_t sector, size_t sector_count,
void* buffer, uint64_t* lockflags) { void* buffer) {
struct idedrv_request* req = malloc(sizeof(*req)); struct idedrv_request* req = malloc(sizeof(*req));
if (req == NULL) if (req == NULL)
@@ -489,12 +482,12 @@ static int idedrv_do_write_irqs(struct idedrv* idedrv, size_t sector, size_t sec
req->sector_done_count = 1; req->sector_done_count = 1;
spin_unlock(&idedrv->device->lock, *lockflags); intr_enable();
while (!atomic_load(&req->done)) while (!atomic_load(&req->done))
spin_lock_relax(); spin_lock_relax();
spin_lock(&idedrv->device->lock, lockflags); intr_disable();
free(req); free(req);
@@ -595,7 +588,7 @@ DEFINE_DEVICE_OP(idedrv_write) {
return -ST_XDRV_WRITE_ERROR; return -ST_XDRV_WRITE_ERROR;
if (idedrv->irqs_support) if (idedrv->irqs_support)
ret = idedrv_do_write_irqs(idedrv, sector, sector_count, buffer, lockflags); ret = idedrv_do_write_irqs(idedrv, sector, sector_count, buffer);
else else
ret = idedrv_do_write_no_irqs(idedrv, sector, sector_count, buffer); ret = idedrv_do_write_no_irqs(idedrv, sector, sector_count, buffer);