diff options
author | Alex Auvolat <alex@adnab.me> | 2015-03-10 20:23:13 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2015-03-10 20:23:13 +0100 |
commit | 0e50ada984473de20ba47c2ebdbe36b3dad78dd1 (patch) | |
tree | 7864cd0290a112244ef93fd590d018e52bbd16a3 /src/kernel/dev | |
parent | 6d9cd139c42a48f5ddf8f8e284f56873de73fd31 (diff) | |
download | kogata-0e50ada984473de20ba47c2ebdbe36b3dad78dd1.tar.gz kogata-0e50ada984473de20ba47c2ebdbe36b3dad78dd1.zip |
Add mutex to pciide driver (fixes some stuff)
Diffstat (limited to 'src/kernel/dev')
-rw-r--r-- | src/kernel/dev/pciide.c | 29 | ||||
-rw-r--r-- | src/kernel/dev/v86.c | 2 | ||||
-rw-r--r-- | src/kernel/dev/vesa.c | 2 |
3 files changed, 26 insertions, 7 deletions
diff --git a/src/kernel/dev/pciide.c b/src/kernel/dev/pciide.c index 9a78315..d63abb4 100644 --- a/src/kernel/dev/pciide.c +++ b/src/kernel/dev/pciide.c @@ -654,6 +654,7 @@ typedef struct { uint32_t block_size; // ATA: 512, ATAPI: 2048 uint8_t device; uint8_t type; + mutex_t lock; } ide_vfs_dev_t; bool ide_vfs_open(fs_node_t *n, int mode); @@ -688,6 +689,7 @@ void ide_register_device(ide_controller_t *c, uint8_t device, fs_t *iofs) { d->device = device; d->type = c->devices[device].type; d->block_size = (d->type == IDE_ATAPI ? 2048 : 512); + d->lock = MUTEX_UNLOCKED; char name[40]; @@ -734,10 +736,17 @@ size_t ide_vfs_read(fs_handle_t *h, size_t offset, size_t len, char* buf) { if (offset % d->block_size != 0) return 0; if (len % d->block_size != 0) return 0; + size_t ret = 0; + mutex_lock(&d->lock); + uint8_t err = ide_read_sectors(d->c, d->device, offset / d->block_size, len / d->block_size, buf); - if (err != 0) return 0; + if (err != 0) goto end; + + ret = len; - return len; +end: + mutex_unlock(&d->lock); + return ret; } size_t ide_vfs_write(fs_handle_t *h, size_t offset, size_t len, const char* buf) { @@ -745,11 +754,19 @@ size_t ide_vfs_write(fs_handle_t *h, size_t offset, size_t len, const char* buf) if (offset % d->block_size != 0) return 0; if (len % d->block_size != 0) return 0; -uint8_t err = ide_write_sectors(d->c, d->device, - offset / d->block_size, len / d->block_size, (char*)buf); - if (err != 0) return 0; - return len; + size_t ret = 0; + mutex_lock(&d->lock); + + uint8_t err = ide_write_sectors(d->c, d->device, + offset / d->block_size, len / d->block_size, (char*)buf); + if (err != 0) goto end; + + ret = len; + +end: + mutex_unlock(&d->lock); + return ret; } int ide_vfs_ioctl(fs_handle_t *h, int command, void* data) { diff --git a/src/kernel/dev/v86.c b/src/kernel/dev/v86.c index db84a4f..1838e92 100644 --- a/src/kernel/dev/v86.c +++ b/src/kernel/dev/v86.c @@ -117,6 +117,8 @@ void v86_run_bios_int(uint32_t int_no) { } void v86_thread_main(void* z) { + enter_critical(CL_NOSWITCH); + if (z) v86_retval = true; wait_on(current_thread); diff --git a/src/kernel/dev/vesa.c b/src/kernel/dev/vesa.c index e60cc98..67a6d70 100644 --- a/src/kernel/dev/vesa.c +++ b/src/kernel/dev/vesa.c @@ -356,7 +356,7 @@ fail_setup: } bool vesa_open(fs_node_t *n, int mode) { - int ok_modes = FM_READ | FM_WRITE | FM_MMAP; + int ok_modes = FM_READ | FM_WRITE | FM_MMAP | FM_IOCTL; if (mode & ~ok_modes) return false; return true; |