summaryrefslogtreecommitdiff
path: root/kernel/drivers
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-03-17 20:55:34 +0100
committerAnton Kling <anton@kling.gg>2024-03-17 20:55:34 +0100
commit0dccff86e50dfe1555b8bc29862dba2b972a3705 (patch)
tree8d0c354c65278afdc3427bb52e1e63900ccdbc05 /kernel/drivers
parent2e8b474d4219e7faaac3823e73c8d528c2698a37 (diff)
stuff
Diffstat (limited to 'kernel/drivers')
-rw-r--r--kernel/drivers/ahci.c34
-rw-r--r--kernel/drivers/keyboard.c1
-rw-r--r--kernel/drivers/mouse.c2
-rw-r--r--kernel/drivers/pst.c4
4 files changed, 28 insertions, 13 deletions
diff --git a/kernel/drivers/ahci.c b/kernel/drivers/ahci.c
index 5a65408..f655709 100644
--- a/kernel/drivers/ahci.c
+++ b/kernel/drivers/ahci.c
@@ -2,6 +2,7 @@
#include <drivers/pci.h>
#include <fs/devfs.h>
#include <fs/vfs.h>
+#include <math.h>
#include <mmu.h>
#include <stdio.h>
@@ -312,7 +313,7 @@ u8 ahci_perform_command(volatile struct HBA_PORT *port, u32 startl, u32 starth,
u8 err;
u32 command_slot = get_free_command_slot(port, &err);
if (err) {
- klog("No command slot found", LOG_WARN);
+ klog("AHCI No command slot found", LOG_WARN);
return 0;
}
struct HBA_CMD_HEADER *cmdheader =
@@ -372,7 +373,7 @@ u8 ahci_perform_command(volatile struct HBA_PORT *port, u32 startl, u32 starth,
spin++;
}
if (spin == 10000) {
- kprintf("Port is hung\n");
+ klog("AHCI port is hung", LOG_ERROR);
return 0;
}
@@ -385,16 +386,15 @@ u8 ahci_perform_command(volatile struct HBA_PORT *port, u32 startl, u32 starth,
if ((port->ci & (1 << command_slot)) == 0) {
break;
}
- if (port->is & HBA_PxIS_TFES) // Task file error
- {
- kprintf("Read disk error\n");
+ if (port->is & HBA_PxIS_TFES) {
+ klog("AHCI command failed", LOG_ERROR);
return 0;
}
}
// Check again
if (port->is & HBA_PxIS_TFES) {
- kprintf("Read disk error\n");
+ klog("AHCI command failed", LOG_ERROR);
return 0;
}
@@ -417,21 +417,37 @@ int ahci_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {
assert(port == 0);
u32 lba = offset / 512;
offset %= 512;
- int rc = len;
+ const int rc = len;
u32 sector_count = len / 512;
if (len % 512 != 0) {
sector_count++;
}
+
+ if (offset > 0) {
+ u8 tmp_buffer[512];
+ ahci_raw_read(&hba->ports[port], lba, 0, 1, (u16 *)tmp_buffer);
+
+ int left = 512 - offset;
+ int write = min(left, len);
+
+ memcpy(tmp_buffer + offset, buffer, write);
+ ahci_raw_write(&hba->ports[port], lba, 0, 1, (u16 *)tmp_buffer);
+
+ offset = 0;
+ len -= write;
+ sector_count--;
+ lba++;
+ }
+
for (; sector_count >= num_prdt; lba++) {
ahci_raw_write(&hba->ports[port], lba, 0, num_prdt, (u16 *)buffer);
- offset = 0;
buffer += num_prdt * 512;
len -= num_prdt * 512;
sector_count -= num_prdt;
}
- if (sector_count > 0) {
+ if (sector_count > 0 && len > 0) {
u8 tmp_buffer[512 * num_prdt];
ahci_raw_read(&hba->ports[port], lba, 0, sector_count, (u16 *)tmp_buffer);
memcpy(tmp_buffer + offset, buffer, len);
diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c
index ec87390..7d35dc1 100644
--- a/kernel/drivers/keyboard.c
+++ b/kernel/drivers/keyboard.c
@@ -185,7 +185,6 @@ int keyboard_read(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {
}
void add_keyboard(void) {
- kprintf("very important");
kb_inode = devfs_add_file("/keyboard", keyboard_read, NULL, NULL, 0, 0,
FS_TYPE_CHAR_DEVICE);
}
diff --git a/kernel/drivers/mouse.c b/kernel/drivers/mouse.c
index a829318..7096ae9 100644
--- a/kernel/drivers/mouse.c
+++ b/kernel/drivers/mouse.c
@@ -42,7 +42,7 @@ void add_mouse(void) {
mouse_inode->internal_object = create_fifo_object();
// Don't look at this
int fd = vfs_open("/dev/mouse", O_RDWR, 0);
- mouse_fd = get_vfs_fd(fd);
+ mouse_fd = get_vfs_fd(fd, NULL);
current_task->file_descriptors[fd] = NULL;
}
diff --git a/kernel/drivers/pst.c b/kernel/drivers/pst.c
index f8a0414..77b1b8b 100644
--- a/kernel/drivers/pst.c
+++ b/kernel/drivers/pst.c
@@ -12,8 +12,8 @@ int openpty(int *amaster, int *aslave, char *name,
pipe(fd); // This depends upon that pipe will support read and write
// through the same fd. In reality this should not be the
// case.
- get_vfs_fd(fd[0])->is_tty = 1;
- get_vfs_fd(fd[1])->is_tty = 1;
+ get_vfs_fd(fd[0], NULL)->is_tty = 1;
+ get_vfs_fd(fd[1], NULL)->is_tty = 1;
*amaster = fd[0];
*aslave = fd[1];
return 0;