Spinlock save cpu flags
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
#include <status.h>
|
||||
#include <sys/debug.h>
|
||||
|
||||
bool debugconsole_init (struct device* device, void* arg, struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
bool debugconsole_init (struct device* device, void* arg, struct proc* proc,
|
||||
struct reschedule_ctx* rctx) {
|
||||
(void)device, (void)arg, (void)proc, (void)rctx;
|
||||
return true;
|
||||
}
|
||||
@@ -18,6 +19,7 @@ void debugconsole_fini (struct device* device, struct proc* proc, struct resched
|
||||
int debugconsole_putstr (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4) {
|
||||
(void)a2, (void)a3, (void)a4, (void)device, (void)rctx;
|
||||
uint64_t fp;
|
||||
|
||||
char* string = (char*)a1;
|
||||
size_t* len = (size_t*)a2;
|
||||
@@ -25,9 +27,9 @@ int debugconsole_putstr (struct device* device, struct proc* proc, struct resche
|
||||
if (string == NULL || len == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
|
||||
spin_lock (&proc->lock);
|
||||
spin_lock (&proc->lock, &fp);
|
||||
int pid = proc->pid;
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&proc->lock, fp);
|
||||
|
||||
debugprintf ("(CPU %d; PID %d) %.*s\n", thiscpu->id, pid, (int)*len, string);
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
struct device;
|
||||
|
||||
bool debugconsole_init (struct device* device, void* arg, struct proc* proc, struct reschedule_ctx* rctx);
|
||||
bool debugconsole_init (struct device* device, void* arg, struct proc* proc,
|
||||
struct reschedule_ctx* rctx);
|
||||
|
||||
void debugconsole_fini (struct device* device, struct proc* proc, struct reschedule_ctx* rctx);
|
||||
|
||||
|
||||
@@ -33,14 +33,16 @@ struct device_table {
|
||||
static struct device_table device_table;
|
||||
|
||||
struct device* device_find (const char* key) {
|
||||
uint64_t fdt;
|
||||
|
||||
struct hash_node_link* found_link = NULL;
|
||||
size_t key_len = strlen_null (key);
|
||||
uint32_t hash = hash_fnv32 (key, key_len);
|
||||
|
||||
spin_lock (&device_table.lock);
|
||||
spin_lock (&device_table.lock, &fdt);
|
||||
hash_find (&device_table, key, key_len, hash, lengthof (device_table.device_buckets),
|
||||
device_buckets, struct device, device_table_link, key, found_link);
|
||||
spin_unlock (&device_table.lock);
|
||||
spin_unlock (&device_table.lock, fdt);
|
||||
|
||||
if (found_link == NULL)
|
||||
return NULL;
|
||||
@@ -51,6 +53,8 @@ struct device* device_find (const char* key) {
|
||||
struct device* device_create (const char* key, device_op_func_t* ops, size_t ops_len,
|
||||
device_init_func_t init, device_fini_func_t fini, void* arg,
|
||||
struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
uint64_t fdt;
|
||||
|
||||
if (ops_len >= fieldlengthof (struct device, ops))
|
||||
return NULL;
|
||||
|
||||
@@ -75,12 +79,12 @@ struct device* device_create (const char* key, device_op_func_t* ops, size_t ops
|
||||
|
||||
uint32_t device_hash = hash_fnv32 (device->key, strlen_null (device->key));
|
||||
|
||||
spin_lock (&device_table.lock);
|
||||
spin_lock (&device_table.lock, &fdt);
|
||||
|
||||
hash_insert (&device_table, &device->device_table_link, device_hash,
|
||||
lengthof (device_table.device_buckets), device_buckets);
|
||||
|
||||
spin_unlock (&device_table.lock);
|
||||
spin_unlock (&device_table.lock, fdt);
|
||||
|
||||
DEBUG ("Created device %s\n", device->key);
|
||||
|
||||
@@ -94,7 +98,8 @@ static void debugconsole_device_init (void) {
|
||||
device_op_func_t ops[] = {
|
||||
[DEBUGCONSOLE_PUTSTR] = &debugconsole_putstr,
|
||||
};
|
||||
device_create ("DEBUGCONSOLE", ops, lengthof (ops), &debugconsole_init, &debugconsole_fini, NULL, thiscpu->kproc, &rctx);
|
||||
device_create ("DEBUGCONSOLE", ops, lengthof (ops), &debugconsole_init, &debugconsole_fini, NULL,
|
||||
thiscpu->kproc, &rctx);
|
||||
}
|
||||
|
||||
static void terminal_device_init (void) {
|
||||
@@ -105,7 +110,8 @@ static void terminal_device_init (void) {
|
||||
[TERMINAL_PUTSTR] = &terminal_putstr,
|
||||
[TERMINAL_DIMENSIONS] = &terminal_dimensions,
|
||||
};
|
||||
device_create ("TERMINAL", ops, lengthof (ops), &terminal_init, &terminal_fini, NULL, thiscpu->kproc, &rctx);
|
||||
device_create ("TERMINAL", ops, lengthof (ops), &terminal_init, &terminal_fini, NULL,
|
||||
thiscpu->kproc, &rctx);
|
||||
}
|
||||
|
||||
static void ramdisk_device_init (void) {
|
||||
@@ -149,7 +155,8 @@ static void ramdisk_device_init (void) {
|
||||
.sector_size = 512,
|
||||
.buffer = unpack_buffer,
|
||||
};
|
||||
device_create ("RD0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init, thiscpu->kproc, &rctx);
|
||||
device_create ("RD0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init, thiscpu->kproc,
|
||||
&rctx);
|
||||
|
||||
LZ4F_freeDecompressionContext (dctx);
|
||||
}
|
||||
@@ -170,7 +177,8 @@ static void temp_device_init (void) {
|
||||
.total_size = 1024 * 1024 * 20,
|
||||
.sector_size = 512,
|
||||
};
|
||||
device_create ("TEMP0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init, thiscpu->kproc, &rctx);
|
||||
device_create ("TEMP0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init, thiscpu->kproc,
|
||||
&rctx);
|
||||
}
|
||||
|
||||
#if defined(__x86_64__)
|
||||
|
||||
@@ -22,8 +22,10 @@ struct device;
|
||||
typedef int (*device_op_func_t) (struct device* device, struct proc*, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4);
|
||||
|
||||
typedef bool (*device_init_func_t) (struct device* device, void* arg, struct proc* proc, struct reschedule_ctx* rctx);
|
||||
typedef void (*device_fini_func_t) (struct device* device, struct proc* proc, struct reschedule_ctx* rctx);
|
||||
typedef bool (*device_init_func_t) (struct device* device, void* arg, struct proc* proc,
|
||||
struct reschedule_ctx* rctx);
|
||||
typedef void (*device_fini_func_t) (struct device* device, struct proc* proc,
|
||||
struct reschedule_ctx* rctx);
|
||||
|
||||
struct device {
|
||||
char key[0x100];
|
||||
|
||||
@@ -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; */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef _KERNEL_DEVICE_IDEDRV_H
|
||||
#define _KERNEL_DEVICE_IDEDRV_H
|
||||
|
||||
#include <libk/std.h>
|
||||
#include <libk/list.h>
|
||||
#include <libk/std.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/reschedule.h>
|
||||
#include <proc/suspension_q.h>
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
#include <proc/reschedule.h>
|
||||
#include <status.h>
|
||||
|
||||
bool partdrv_init (struct device* device, void* arg, struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
bool partdrv_init (struct device* device, void* arg, struct proc* proc,
|
||||
struct reschedule_ctx* rctx) {
|
||||
(void)proc, (void)rctx;
|
||||
|
||||
struct partdrv_init* init = arg;
|
||||
@@ -36,6 +37,7 @@ void partdrv_fini (struct device* device, struct proc* proc, struct reschedule_c
|
||||
int partdrv_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 fs;
|
||||
|
||||
if (a1 == NULL || a2 == NULL || a3 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
@@ -47,9 +49,9 @@ int partdrv_read (struct device* device, struct proc* proc, struct reschedule_ct
|
||||
size_t sector_count = *(size_t*)a2;
|
||||
uint8_t* buffer = a3;
|
||||
|
||||
spin_lock (&super->lock);
|
||||
spin_lock (&super->lock, &fs);
|
||||
int ret = device_op (super, XDRV_READ, proc, rctx, §or, §or_count, buffer);
|
||||
spin_unlock (&super->lock);
|
||||
spin_unlock (&super->lock, fs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -57,6 +59,7 @@ int partdrv_read (struct device* device, struct proc* proc, struct reschedule_ct
|
||||
int partdrv_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 fs;
|
||||
|
||||
if (a1 == NULL || a2 == NULL || a3 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
@@ -68,9 +71,9 @@ int partdrv_write (struct device* device, struct proc* proc, struct reschedule_c
|
||||
size_t sector_count = *(size_t*)a2;
|
||||
uint8_t* buffer = a3;
|
||||
|
||||
spin_lock (&super->lock);
|
||||
spin_lock (&super->lock, &fs);
|
||||
int ret = device_op (super, XDRV_WRITE, proc, rctx, §or, §or_count, buffer);
|
||||
spin_unlock (&super->lock);
|
||||
spin_unlock (&super->lock, fs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -92,6 +95,7 @@ int partdrv_get_device_type (struct device* device, struct proc* proc, struct re
|
||||
int partdrv_get_sector_size (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4) {
|
||||
(void)proc, (void)rctx, (void)a2, (void)a3, (void)a4;
|
||||
uint64_t fs;
|
||||
|
||||
if (a1 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
@@ -100,9 +104,9 @@ int partdrv_get_sector_size (struct device* device, struct proc* proc, struct re
|
||||
|
||||
struct partdrv* partdrv = device->udata;
|
||||
|
||||
spin_lock (&partdrv->super->lock);
|
||||
spin_lock (&partdrv->super->lock, &fs);
|
||||
device_op (partdrv->super, XDRV_GET_SECTOR_SIZE, proc, rctx, secsize);
|
||||
spin_unlock (&partdrv->super->lock);
|
||||
spin_unlock (&partdrv->super->lock, fs);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ struct partdrv {
|
||||
size_t total_size;
|
||||
};
|
||||
|
||||
bool partdrv_init (struct device* device, void* arg, struct proc* proc, struct reschedule_ctx* rctx);
|
||||
bool partdrv_init (struct device* device, void* arg, struct proc* proc,
|
||||
struct reschedule_ctx* rctx);
|
||||
|
||||
void partdrv_fini (struct device* device, struct proc* proc, struct reschedule_ctx* rctx);
|
||||
|
||||
|
||||
@@ -7,12 +7,15 @@
|
||||
#include <libk/printf.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <status.h>
|
||||
#include <sys/debug.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/reschedule.h>
|
||||
#include <status.h>
|
||||
#include <sys/debug.h>
|
||||
|
||||
static int device_probe_partitions_dos (struct proc* proc, struct reschedule_ctx* rctx,
|
||||
struct device* device) {
|
||||
uint64_t fd;
|
||||
|
||||
static int device_probe_partitions_dos (struct proc* proc, struct reschedule_ctx* rctx, struct device* device) {
|
||||
struct dos_mbr mbr;
|
||||
memset (&mbr, 0, sizeof (mbr));
|
||||
size_t sector = 0;
|
||||
@@ -27,19 +30,19 @@ static int device_probe_partitions_dos (struct proc* proc, struct reschedule_ctx
|
||||
[XDRV_WRITE] = &partdrv_write,
|
||||
};
|
||||
|
||||
spin_lock (&device->lock);
|
||||
spin_lock (&device->lock, &fd);
|
||||
|
||||
device_op (device, XDRV_GET_SECTOR_SIZE, proc, rctx, §or_size);
|
||||
|
||||
int ret = device_op (device, XDRV_READ, proc, rctx, §or, §or_count, &mbr);
|
||||
|
||||
if (ret < 0) {
|
||||
spin_unlock (&device->lock);
|
||||
spin_unlock (&device->lock, fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!(mbr.valid_sign[0] == 0x55 && mbr.valid_sign[1] == 0xAA)) {
|
||||
spin_unlock (&device->lock);
|
||||
spin_unlock (&device->lock, fd);
|
||||
return -ST_PARTITION_ERROR;
|
||||
}
|
||||
|
||||
@@ -59,9 +62,12 @@ static int device_probe_partitions_dos (struct proc* proc, struct reschedule_ctx
|
||||
device_create (key, ops, lengthof (ops), &partdrv_init, &partdrv_fini, &init, proc, rctx);
|
||||
}
|
||||
|
||||
spin_unlock (&device->lock);
|
||||
spin_unlock (&device->lock, fd);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
int device_probe_partitions (struct proc* proc, struct reschedule_ctx* rctx, struct device* device) { return device_probe_partitions_dos (proc, rctx, device); }
|
||||
int device_probe_partitions (struct proc* proc, struct reschedule_ctx* rctx,
|
||||
struct device* device) {
|
||||
return device_probe_partitions_dos (proc, rctx, device);
|
||||
}
|
||||
|
||||
@@ -16,86 +16,100 @@ static const struct pci_driver_info pci_driver_infos[] = {
|
||||
static spin_lock_t pci_lock = SPIN_LOCK_INIT;
|
||||
|
||||
uint32_t pci_read32 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) {
|
||||
uint64_t fpci;
|
||||
|
||||
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
|
||||
(offset & 0xFC) | ((uint32_t)0x80000000);
|
||||
|
||||
spin_lock (&pci_lock);
|
||||
spin_lock (&pci_lock, &fpci);
|
||||
|
||||
outl (PCI_CONFIG_ADDR, addr);
|
||||
uint32_t r = inl (PCI_CONFIG_DATA);
|
||||
|
||||
spin_unlock (&pci_lock);
|
||||
spin_unlock (&pci_lock, fpci);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void pci_write32 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint32_t value) {
|
||||
uint64_t fpci;
|
||||
|
||||
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
|
||||
(offset & 0xFC) | ((uint32_t)0x80000000);
|
||||
|
||||
spin_lock (&pci_lock);
|
||||
spin_lock (&pci_lock, &fpci);
|
||||
|
||||
outl (PCI_CONFIG_ADDR, addr);
|
||||
outl (PCI_CONFIG_DATA, value);
|
||||
|
||||
spin_unlock (&pci_lock);
|
||||
spin_unlock (&pci_lock, fpci);
|
||||
}
|
||||
|
||||
uint16_t pci_read16 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) {
|
||||
uint64_t fpci;
|
||||
|
||||
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
|
||||
(offset & 0xFC) | ((uint32_t)0x80000000);
|
||||
|
||||
spin_lock (&pci_lock);
|
||||
spin_lock (&pci_lock, &fpci);
|
||||
|
||||
outl (PCI_CONFIG_ADDR, addr);
|
||||
uint16_t r = inw (PCI_CONFIG_DATA + (offset & 2));
|
||||
|
||||
spin_unlock (&pci_lock);
|
||||
spin_unlock (&pci_lock, fpci);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void pci_write16 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint16_t value) {
|
||||
uint64_t fpci;
|
||||
|
||||
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
|
||||
(offset & 0xFC) | ((uint32_t)0x80000000);
|
||||
|
||||
spin_lock (&pci_lock);
|
||||
spin_lock (&pci_lock, &fpci);
|
||||
|
||||
outl (PCI_CONFIG_ADDR, addr);
|
||||
outw (PCI_CONFIG_DATA + (offset & 2), value);
|
||||
|
||||
spin_unlock (&pci_lock);
|
||||
spin_unlock (&pci_lock, fpci);
|
||||
}
|
||||
|
||||
uint8_t pci_read8 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) {
|
||||
uint64_t fpci;
|
||||
|
||||
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
|
||||
(offset & 0xFC) | ((uint32_t)0x80000000);
|
||||
|
||||
spin_lock (&pci_lock);
|
||||
spin_lock (&pci_lock, &fpci);
|
||||
|
||||
outl (PCI_CONFIG_ADDR, addr);
|
||||
uint8_t r = inb (PCI_CONFIG_DATA + (offset & 3));
|
||||
|
||||
spin_unlock (&pci_lock);
|
||||
spin_unlock (&pci_lock, fpci);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void pci_write8 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint8_t value) {
|
||||
uint64_t fpci;
|
||||
|
||||
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
|
||||
(offset & 0xFC) | ((uint32_t)0x80000000);
|
||||
|
||||
spin_lock (&pci_lock);
|
||||
spin_lock (&pci_lock, &fpci);
|
||||
|
||||
outl (PCI_CONFIG_ADDR, addr);
|
||||
outb (PCI_CONFIG_DATA + (offset & 3), value);
|
||||
|
||||
spin_unlock (&pci_lock);
|
||||
spin_unlock (&pci_lock, fpci);
|
||||
}
|
||||
|
||||
static void pci_check_bus (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus, pci_cb_func_t cb);
|
||||
static void pci_check_bus (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus,
|
||||
pci_cb_func_t cb);
|
||||
|
||||
static void pci_check_func (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus, uint8_t slot, uint8_t func, pci_cb_func_t cb) {
|
||||
static void pci_check_func (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus,
|
||||
uint8_t slot, uint8_t func, pci_cb_func_t cb) {
|
||||
uint32_t reg0 = pci_read32 (bus, slot, func, PCI_VENDOR_ID);
|
||||
uint16_t vendor = (uint16_t)(reg0 & 0xFFFF);
|
||||
|
||||
@@ -124,7 +138,8 @@ static void pci_check_func (struct proc* proc, struct reschedule_ctx* rctx, uint
|
||||
}
|
||||
}
|
||||
|
||||
static void pci_check_device (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus, uint8_t slot, pci_cb_func_t cb) {
|
||||
static void pci_check_device (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus,
|
||||
uint8_t slot, pci_cb_func_t cb) {
|
||||
uint32_t reg0 = pci_read32 (bus, slot, 0, PCI_VENDOR_ID);
|
||||
|
||||
if ((uint16_t)(reg0 & 0xFFFF) == 0xFFFF)
|
||||
@@ -140,7 +155,8 @@ static void pci_check_device (struct proc* proc, struct reschedule_ctx* rctx, ui
|
||||
}
|
||||
}
|
||||
|
||||
static void pci_check_bus (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus, pci_cb_func_t cb) {
|
||||
static void pci_check_bus (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus,
|
||||
pci_cb_func_t cb) {
|
||||
for (uint8_t slot = 0; slot < 32; slot++)
|
||||
pci_check_device (proc, rctx, bus, slot, cb);
|
||||
}
|
||||
@@ -188,7 +204,8 @@ static void pci_string_identifiers (uint16_t vendor_id, uint16_t device_id, uint
|
||||
}
|
||||
}
|
||||
|
||||
static void pci_discovery_cb (struct proc* proc, struct reschedule_ctx* rctx, struct pci_info pci_info) {
|
||||
static void pci_discovery_cb (struct proc* proc, struct reschedule_ctx* rctx,
|
||||
struct pci_info pci_info) {
|
||||
const char *vname, *dname, *cname;
|
||||
pci_string_identifiers (pci_info.vendor, pci_info.device, pci_info.class, pci_info.subclass,
|
||||
&vname, &dname, &cname);
|
||||
|
||||
@@ -58,7 +58,8 @@ struct pci_driver_info {
|
||||
bool (*init) (struct proc* proc, struct reschedule_ctx* rctx, struct pci_info pci_info);
|
||||
};
|
||||
|
||||
typedef void (*pci_cb_func_t) (struct proc* proc, struct reschedule_ctx* rctx, struct pci_info pci_info);
|
||||
typedef void (*pci_cb_func_t) (struct proc* proc, struct reschedule_ctx* rctx,
|
||||
struct pci_info pci_info);
|
||||
|
||||
void pci_init (void);
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#include <amd64/io.h>
|
||||
#include <device/device.h>
|
||||
#include <device/idedrv.h>
|
||||
#include <device/partitions.h>
|
||||
#include <device/pci.h>
|
||||
#include <device/pci_info.h>
|
||||
#include <device/partitions.h>
|
||||
#include <devices.h>
|
||||
#include <libk/fieldsizeof.h>
|
||||
#include <libk/lengthof.h>
|
||||
#include <libk/printf.h>
|
||||
#include <libk/std.h>
|
||||
#include <sys/debug.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/reschedule.h>
|
||||
#include <sys/debug.h>
|
||||
|
||||
static atomic_int ide_counter = 0;
|
||||
|
||||
@@ -30,7 +30,8 @@ static const char* progif_msg[] = {
|
||||
"PCI native mode controller, supports both channels switched to ISA compatibility mode, supports bus mastering",
|
||||
};
|
||||
|
||||
static void ide_make_device (struct proc* proc, struct reschedule_ctx* rctx, struct ide_probe probe) {
|
||||
static void ide_make_device (struct proc* proc, struct reschedule_ctx* rctx,
|
||||
struct ide_probe probe) {
|
||||
DEBUG ("Found IDE drive: io=%x ctrl=%x no=%u sector=%zu count=%zu\n", probe.io, probe.ctrl,
|
||||
probe.devno, probe.sector_size, probe.sector_count);
|
||||
|
||||
@@ -54,7 +55,8 @@ static void ide_make_device (struct proc* proc, struct reschedule_ctx* rctx, str
|
||||
.devno = probe.devno,
|
||||
.primscnd = probe.primscnd,
|
||||
};
|
||||
struct device* ide = device_create (device_key, ops, lengthof (ops), &idedrv_init, &idedrv_fini, &init, proc, rctx);
|
||||
struct device* ide = device_create (device_key, ops, lengthof (ops), &idedrv_init, &idedrv_fini,
|
||||
&init, proc, rctx);
|
||||
device_probe_partitions (proc, rctx, ide);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,14 +148,15 @@ static int32_t ps2kb_keycode (void) {
|
||||
|
||||
static void ps2kb_irq (void* arg, void* regs, struct reschedule_ctx* rctx) {
|
||||
(void)arg, (void)regs;
|
||||
uint64_t frb, fsq;
|
||||
|
||||
int32_t keycode = ps2kb_keycode ();
|
||||
|
||||
if (keycode <= 0 || keycode == 0xFA)
|
||||
return;
|
||||
|
||||
spin_lock (&ps2kb_ringbuffer_lock);
|
||||
spin_lock (&ps2kb_sq.lock);
|
||||
spin_lock (&ps2kb_ringbuffer_lock, &frb);
|
||||
spin_lock (&ps2kb_sq.lock, &fsq);
|
||||
|
||||
ringbuffer_push (uint8_t, &ps2kb_ringbuffer, (uint8_t)keycode);
|
||||
|
||||
@@ -165,20 +166,21 @@ static void ps2kb_irq (void* arg, void* regs, struct reschedule_ctx* rctx) {
|
||||
struct proc_sq_entry* sq_entry = list_entry (node, struct proc_sq_entry, sq_link);
|
||||
struct proc* resumed_proc = sq_entry->proc;
|
||||
|
||||
spin_unlock (&ps2kb_sq.lock);
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
spin_unlock (&ps2kb_sq.lock, fsq);
|
||||
spin_unlock (&ps2kb_ringbuffer_lock, frb);
|
||||
|
||||
proc_sq_resume (resumed_proc, sq_entry, rctx);
|
||||
return;
|
||||
}
|
||||
|
||||
spin_unlock (&ps2kb_sq.lock);
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
spin_unlock (&ps2kb_sq.lock, fsq);
|
||||
spin_unlock (&ps2kb_ringbuffer_lock, frb);
|
||||
}
|
||||
|
||||
int ps2kb_read_key (struct device* device, struct proc* proc, struct reschedule_ctx* rctx, void* a1,
|
||||
void* a2, void* a3, void* a4) {
|
||||
(void)device, (void)a2, (void)a3, (void)a4;
|
||||
uint64_t frb, fsq;
|
||||
|
||||
if (!(proc->procgroup->capabilities & PROC_CAP_KB))
|
||||
return -ST_PERMISSION_ERROR;
|
||||
@@ -188,7 +190,7 @@ int ps2kb_read_key (struct device* device, struct proc* proc, struct reschedule_
|
||||
if (chbuf == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
|
||||
spin_lock (&ps2kb_ringbuffer_lock);
|
||||
spin_lock (&ps2kb_ringbuffer_lock, &frb);
|
||||
|
||||
size_t prev_count = ps2kb_ringbuffer.count;
|
||||
|
||||
@@ -198,21 +200,21 @@ int ps2kb_read_key (struct device* device, struct proc* proc, struct reschedule_
|
||||
|
||||
/* didn't pop anything */
|
||||
if (prev_count == new_count) {
|
||||
spin_lock (&ps2kb_sq.lock);
|
||||
spin_lock (&ps2kb_sq.lock, &fsq);
|
||||
struct list_node_link* node = ps2kb_sq.proc_list;
|
||||
spin_unlock (&ps2kb_sq.lock);
|
||||
spin_unlock (&ps2kb_sq.lock, fsq);
|
||||
|
||||
if (node != NULL) {
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
spin_unlock (&ps2kb_ringbuffer_lock, frb);
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
proc_sq_suspend (proc, &ps2kb_sq, &ps2kb_ringbuffer_lock, rctx);
|
||||
proc_sq_suspend (proc, &ps2kb_sq, &ps2kb_ringbuffer_lock, frb, rctx);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
spin_unlock (&ps2kb_ringbuffer_lock, frb);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
#include <status.h>
|
||||
#include <sys/debug.h>
|
||||
|
||||
bool ramdrv_init (struct device* device, void* arg, struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
bool ramdrv_init (struct device* device, void* arg, struct proc* proc,
|
||||
struct reschedule_ctx* rctx) {
|
||||
(void)proc, (void)rctx;
|
||||
struct ramdrv_init* init = arg;
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ void ft_free (void* ptr, size_t size) {
|
||||
free (ptr);
|
||||
}
|
||||
|
||||
bool terminal_init (struct device* device, void* arg, struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
bool terminal_init (struct device* device, void* arg, struct proc* proc,
|
||||
struct reschedule_ctx* rctx) {
|
||||
(void)arg, (void)device, (void)proc, (void)rctx;
|
||||
|
||||
struct limine_framebuffer_response* fb_r = limine_framebuffer_request.response;
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
|
||||
struct device;
|
||||
|
||||
bool terminal_init (struct device* device, void* arg, struct proc* proc, struct reschedule_ctx* rctx);
|
||||
bool terminal_init (struct device* device, void* arg, struct proc* proc,
|
||||
struct reschedule_ctx* rctx);
|
||||
|
||||
void terminal_fini (struct device* device, struct proc* proc, struct reschedule_ctx* rctx);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user