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 | |
parent | 6d9cd139c42a48f5ddf8f8e284f56873de73fd31 (diff) | |
download | kogata-0e50ada984473de20ba47c2ebdbe36b3dad78dd1.tar.gz kogata-0e50ada984473de20ba47c2ebdbe36b3dad78dd1.zip |
Add mutex to pciide driver (fixes some stuff)
-rw-r--r-- | src/kernel/core/thread.c | 2 | ||||
-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 | ||||
-rw-r--r-- | src/sysbin/giosrv/main.c | 2 | ||||
-rw-r--r-- | src/tests/utests/rules.make | 2 |
6 files changed, 30 insertions, 9 deletions
diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index 1689433..3086be0 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -124,6 +124,8 @@ void run_scheduler() { } current_thread = dequeue_thread(); + /*dbg_printf("[0x%p]\n", current_thread);*/ + if (current_thread != 0) { thread_t *ptr = current_thread; prng_add_entropy((uint8_t*)&ptr, sizeof(ptr)); 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; diff --git a/src/sysbin/giosrv/main.c b/src/sysbin/giosrv/main.c index ab30664..04e57ea 100644 --- a/src/sysbin/giosrv/main.c +++ b/src/sysbin/giosrv/main.c @@ -11,7 +11,7 @@ int main(int argc, char **argv) { dbg_print("[giosrv] Starting up.\n"); - fd_t fbdev = open("io:/display/vesa", FM_READ | FM_WRITE | FM_MMAP); + fd_t fbdev = open("io:/display/vesa", FM_IOCTL | FM_READ | FM_WRITE | FM_MMAP); if (fbdev == 0) PANIC("Could not open fbdev"); framebuffer_info_t i; diff --git a/src/tests/utests/rules.make b/src/tests/utests/rules.make index 1f4bb1b..3e5fe1c 100644 --- a/src/tests/utests/rules.make +++ b/src/tests/utests/rules.make @@ -3,7 +3,7 @@ LIB = ../../../lib/libkogata/libkogata.lib ../../../common/libc/libc.lib OBJ = test.o CFLAGS = -I . -I ../../../common/include -I ../../../lib/include -DBUILD_USER_TEST -LDFLAGS = -T ../../../apps/linker.ld -Xlinker -Map=init.map +LDFLAGS = -T ../../../sysbin/linker.ld -Xlinker -Map=init.map OUT = init.bin |