Spinlock save cpu flags
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
#include <amd64/io.h>
|
||||
#include <amd64/intr_defs.h>
|
||||
#include <amd64/apic.h>
|
||||
#include <amd64/intr_defs.h>
|
||||
#include <amd64/io.h>
|
||||
#include <device/device.h>
|
||||
#include <device/idedrv.h>
|
||||
#include <device/partitions.h>
|
||||
#include <devices.h>
|
||||
#include <libk/std.h>
|
||||
#include <irq/irq.h>
|
||||
#include <libk/list.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <mm/liballoc.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/reschedule.h>
|
||||
#include <status.h>
|
||||
#include <irq/irq.h>
|
||||
|
||||
#define IDE_REG_DATA 0x00
|
||||
#define IDE_REG_ERROR 0x01
|
||||
@@ -91,15 +91,17 @@ static void ide_flush (struct idedrv* idedrv) {
|
||||
}
|
||||
|
||||
static void ide_irq (void* arg, void* regs, struct reschedule_ctx* rctx) {
|
||||
uint64_t fd, fp;
|
||||
|
||||
struct idedrv* idedrv = arg;
|
||||
|
||||
spin_lock (&idedrv->device->lock);
|
||||
spin_lock (&idedrv->device->lock, &fd);
|
||||
|
||||
struct list_node_link* node = idedrv->requests;
|
||||
|
||||
if (node == NULL) {
|
||||
(void)inb (idedrv->io + IDE_REG_STATUS);
|
||||
spin_unlock (&idedrv->device->lock);
|
||||
spin_unlock (&idedrv->device->lock, fd);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,18 +109,18 @@ static void ide_irq (void* arg, void* regs, struct reschedule_ctx* rctx) {
|
||||
struct list_node_link* sqlist_node = req->sq.proc_list;
|
||||
struct proc_sq_entry* sq_entry = list_entry (sqlist_node, struct proc_sq_entry, sq_link);
|
||||
struct proc* resumed_proc = sq_entry->proc;
|
||||
|
||||
|
||||
uint8_t status = inb (idedrv->io + IDE_REG_STATUS);
|
||||
|
||||
if ((status & (IDE_ERR | IDE_DRQ))) {
|
||||
list_remove (idedrv->requests, &req->requests_link);
|
||||
spin_unlock (&idedrv->device->lock);
|
||||
spin_unlock (&idedrv->device->lock, fd);
|
||||
proc_sq_resume (resumed_proc, sq_entry, rctx);
|
||||
free (req);
|
||||
return;
|
||||
}
|
||||
|
||||
spin_lock (&resumed_proc->lock);
|
||||
spin_lock (&resumed_proc->lock, &fp);
|
||||
|
||||
if (req->rw == 1) {
|
||||
if ((status & IDE_DRQ)) {
|
||||
@@ -140,16 +142,16 @@ static void ide_irq (void* arg, void* regs, struct reschedule_ctx* rctx) {
|
||||
|
||||
list_remove (idedrv->requests, &req->requests_link);
|
||||
|
||||
spin_unlock (&resumed_proc->lock);
|
||||
spin_unlock (&idedrv->device->lock);
|
||||
spin_unlock (&resumed_proc->lock, fp);
|
||||
spin_unlock (&idedrv->device->lock, fd);
|
||||
|
||||
free (req);
|
||||
proc_sq_resume (resumed_proc, sq_entry, rctx);
|
||||
return;
|
||||
}
|
||||
|
||||
spin_unlock (&resumed_proc->lock);
|
||||
spin_unlock (&idedrv->device->lock);
|
||||
spin_unlock (&resumed_proc->lock, fp);
|
||||
spin_unlock (&idedrv->device->lock, fd);
|
||||
}
|
||||
|
||||
void ide_probe (uint16_t io, uint16_t ctrl, uint8_t devno, struct ide_probe* probe) {
|
||||
@@ -244,7 +246,8 @@ static void ide_prepare (struct idedrv* idedrv, size_t sector, uint16_t sector_c
|
||||
}
|
||||
}
|
||||
|
||||
bool idedrv_init (struct device* device, void* arg, struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
bool idedrv_init (struct device* device, void* arg, struct proc* proc,
|
||||
struct reschedule_ctx* rctx) {
|
||||
(void)proc, (void)rctx;
|
||||
|
||||
struct idedrv_init* init = arg;
|
||||
@@ -279,7 +282,7 @@ bool idedrv_init (struct device* device, void* arg, struct proc* proc, struct re
|
||||
void idedrv_fini (struct device* device, struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
struct idedrv* idedrv = device->udata;
|
||||
|
||||
struct list_node_link* req_link, *tmp_req_link;
|
||||
struct list_node_link *req_link, *tmp_req_link;
|
||||
list_foreach (idedrv->requests, req_link, tmp_req_link) {
|
||||
struct idedrv_request* req = list_entry (req_link, struct idedrv_request, requests_link);
|
||||
list_remove (idedrv->requests, &req->requests_link);
|
||||
@@ -295,6 +298,7 @@ void idedrv_fini (struct device* device, struct proc* proc, struct reschedule_ct
|
||||
int idedrv_read (struct device* device, struct proc* proc, struct reschedule_ctx* rctx, void* a1,
|
||||
void* a2, void* a3, void* a4) {
|
||||
(void)proc, (void)rctx, (void)a4;
|
||||
uint64_t fp;
|
||||
|
||||
if (a1 == NULL || a2 == NULL || a3 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
@@ -308,25 +312,26 @@ int idedrv_read (struct device* device, struct proc* proc, struct reschedule_ctx
|
||||
if (sector + sector_count > idedrv->sector_count)
|
||||
return -ST_OOB_ERROR;
|
||||
|
||||
spin_lock (&proc->lock);
|
||||
spin_lock (&proc->lock, &fp);
|
||||
bool is_kproc = (proc->flags & PROC_KPROC) != 0;
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&proc->lock, fp);
|
||||
|
||||
/* /1* polling *1/ */
|
||||
/* if (is_kproc) { */
|
||||
ide_prepare (idedrv, sector, sector_count, false);
|
||||
ide_prepare (idedrv, sector, sector_count, false);
|
||||
|
||||
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);
|
||||
|
||||
for (uint16_t s = 0; s < sector_count; s++) {
|
||||
if (!ide_wait (idedrv->io, 100000, true, true))
|
||||
return -ST_XDRV_READ_ERROR;
|
||||
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;
|
||||
insw (idedrv->io + IDE_REG_DATA, buffer + (s * (idedrv->sector_size / 2)),
|
||||
(idedrv->sector_size / 2));
|
||||
}
|
||||
|
||||
return ST_OK;
|
||||
/* } else { /1* IRQ *1/ */
|
||||
/* struct idedrv_request* req = malloc (sizeof (*req)); */
|
||||
|
||||
@@ -354,6 +359,7 @@ int idedrv_read (struct device* device, struct proc* proc, struct reschedule_ctx
|
||||
int idedrv_write (struct device* device, struct proc* proc, struct reschedule_ctx* rctx, void* a1,
|
||||
void* a2, void* a3, void* a4) {
|
||||
(void)proc, (void)rctx, (void)a4;
|
||||
uint64_t fp;
|
||||
|
||||
if (a1 == NULL || a2 == NULL || a3 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
@@ -366,26 +372,27 @@ int idedrv_write (struct device* device, struct proc* proc, struct reschedule_ct
|
||||
|
||||
if (sector + sector_count > idedrv->sector_count)
|
||||
return -ST_OOB_ERROR;
|
||||
|
||||
spin_lock (&proc->lock);
|
||||
|
||||
spin_lock (&proc->lock, &fp);
|
||||
bool is_kproc = (proc->flags & PROC_KPROC) != 0;
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&proc->lock, fp);
|
||||
|
||||
/* /1* polling *1/ */
|
||||
/* if (is_kproc) { */
|
||||
ide_prepare (idedrv, sector, sector_count, false);
|
||||
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);
|
||||
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;
|
||||
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 + (s * (idedrv->sector_size / 2)),
|
||||
(idedrv->sector_size / 2));
|
||||
}
|
||||
|
||||
return ST_OK;
|
||||
return ST_OK;
|
||||
/* } else { /1* IRQ *1/ */
|
||||
/* struct idedrv_request* req = malloc (sizeof (*req)); */
|
||||
|
||||
@@ -408,7 +415,8 @@ int idedrv_write (struct device* device, struct proc* proc, struct reschedule_ct
|
||||
|
||||
/* if (!ide_wait (idedrv->io, 100000, true, true)) { */
|
||||
/* list_remove (idedrv->requests, &req->requests_link); */
|
||||
/* struct proc_sq_entry* sq_entry = list_entry (req->sq.proc_list, struct proc_sq_entry, sq_link); */
|
||||
/* struct proc_sq_entry* sq_entry = list_entry (req->sq.proc_list, struct proc_sq_entry,
|
||||
* sq_link); */
|
||||
/* proc_sq_resume (proc, sq_entry, rctx); */
|
||||
/* free (req); */
|
||||
/* return -ST_XDRV_WRITE_ERROR; */
|
||||
|
||||
Reference in New Issue
Block a user