feat: initial locking etc.
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <libc/kprintf.h>
|
||||
#include <fs/blockdev.h>
|
||||
#include <mem/malloc.h>
|
||||
#include <tasks/locking.h>
|
||||
|
||||
#define ATA_SR_BSY 0x80 // Busy
|
||||
#define ATA_SR_DRDY 0x40 // Drive ready
|
||||
@@ -135,6 +136,8 @@ typedef struct {
|
||||
uint8_t print_error: 1;
|
||||
} ide_block_device_info;
|
||||
|
||||
mutex_t *ide_lock = NULL;
|
||||
|
||||
uint8_t ide_read(uint8_t channel, uint8_t reg);
|
||||
|
||||
void ide_write(uint8_t channel, uint8_t reg, uint8_t data);
|
||||
@@ -437,6 +440,12 @@ uint8_t ide_pci_initialize(pci_device *device) {
|
||||
return PCI_INIT_FAIL;
|
||||
}
|
||||
|
||||
if (ide_lock != NULL) {
|
||||
k_panics("IDE already initialized\n");
|
||||
}
|
||||
ide_lock = mutex_create();
|
||||
mutex_acquire(ide_lock);
|
||||
|
||||
// disable IRQ
|
||||
ide_write(ATA_PRIMARY, ATA_REG_CONTROL, 2);
|
||||
ide_write(ATA_SECONDARY, ATA_REG_CONTROL, 2);
|
||||
@@ -518,6 +527,7 @@ uint8_t ide_pci_initialize(pci_device *device) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
mutex_release(ide_lock);
|
||||
ide_register_block_devices();
|
||||
|
||||
return PCI_INIT_OK;
|
||||
@@ -673,5 +683,8 @@ uint8_t ide_access(uint8_t direction, uint8_t drive, uint32_t lba, uint8_t numse
|
||||
|| ide_devices[drive].type == IDE_ATAPI) {
|
||||
return 0xF1;
|
||||
}
|
||||
return ide_read_ata_access(direction, drive, lba, numsects, target);
|
||||
mutex_acquire(ide_lock);
|
||||
uint8_t result = ide_read_ata_access(direction, drive, lba, numsects, target);
|
||||
mutex_release(ide_lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,22 @@ void pci_config_write_byte(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offs
|
||||
port_byte_out(PORT_PCI_CONFIG_DATA, value);
|
||||
}
|
||||
|
||||
pci_command_register_t pci_get_config(pci_device *device) {
|
||||
pci_command_register_t status;
|
||||
status.value = pci_config_read_word(device->bus, device->slot, device->func, PCI_CONFIG_COMMAND);
|
||||
return status;
|
||||
}
|
||||
|
||||
void pci_set_status(pci_device *device, pci_status_register_t status) {
|
||||
pci_config_write_word(device->bus, device->slot, device->func, PCI_CONFIG_STATUS, status.value);
|
||||
}
|
||||
|
||||
pci_status_register_t pci_get_status(pci_device *device) {
|
||||
pci_status_register_t status;
|
||||
status.value = pci_config_read_word(device->bus, device->slot, device->func, PCI_CONFIG_STATUS);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint16_t pci_get_vendor_id(uint8_t bus, uint8_t slot, uint8_t func) {
|
||||
return pci_config_read_word(bus, slot, func, PCI_CONFIG_VENDOR_ID);
|
||||
}
|
||||
@@ -193,6 +209,31 @@ void pci_print_info() {
|
||||
}
|
||||
}
|
||||
|
||||
void pci_dump_caps_internal(pci_device *device) {
|
||||
if (pci_devices->headerType >= 0x02) {
|
||||
printf("\tNot supported for PCI-to-CardBus bridge\n");
|
||||
return;
|
||||
}
|
||||
if (!pci_get_status(device).status.capabilities_list) {
|
||||
printf("\tNo caps\n");
|
||||
return;
|
||||
}
|
||||
uint8_t cap_ptr = pci_config_read_byte(device->bus, device->slot, device->func, PCI_CONFIG_CAP_POINTER);
|
||||
printf("\t%x\n", cap_ptr);
|
||||
// todo traverse
|
||||
}
|
||||
|
||||
void pci_dump_caps() {
|
||||
for (int i = 0; i < last_pci_device_index; ++i) {
|
||||
printf("PCI BSF: %2x/%2x/%2x, CSI: %2x/%2x/%2x, V/D: %4x/%4x, driver: %s\n",
|
||||
pci_devices[i].bus, pci_devices[i].slot, pci_devices[i].func,
|
||||
pci_devices[i].class, pci_devices[i].subclass, pci_devices[i].programInterface,
|
||||
pci_devices[i].vendorId, pci_devices[i].deviceId,
|
||||
(pci_devices[i].pci_driver == NULL ? "none" : pci_devices[i].pci_driver->name));
|
||||
pci_dump_caps_internal(&pci_devices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void pci_init_bar(pci_device *device, uint8_t bar_index) {
|
||||
if (device->headerType != 0x00) {
|
||||
k_panics("Only header 0x00 supported for now");
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#define NEW_KERNEL_PCI_H
|
||||
|
||||
#include <types.h>
|
||||
#include <stdbool.h>
|
||||
#include <attributes.h>
|
||||
|
||||
#define PCI_CLASS_MASS_STORAGE 0x01
|
||||
|
||||
@@ -130,8 +132,47 @@ typedef struct pci_device {
|
||||
} driver_state;
|
||||
} pci_device;
|
||||
|
||||
typedef union {
|
||||
uint16_t value;
|
||||
struct {
|
||||
bool io_space: 1;
|
||||
bool mem_space: 1;
|
||||
bool bus_master: 1;
|
||||
bool special_cycles: 1;
|
||||
bool mem_write_invalidate_enable: 1;
|
||||
bool vga_palette_snoop: 1;
|
||||
bool parity_error_response: 1;
|
||||
uint8_t reserved: 1;
|
||||
bool serr_enable: 1;
|
||||
bool fast_b2b_enable: 1;
|
||||
bool interrupt_disable: 1;
|
||||
uint8_t reserved2: 5;
|
||||
} packed command;
|
||||
} pci_command_register_t;
|
||||
|
||||
typedef union {
|
||||
uint16_t value;
|
||||
struct {
|
||||
uint8_t reserved: 3;
|
||||
bool interrupt_status: 1;
|
||||
bool capabilities_list: 1;
|
||||
bool speed_66mhz_capable: 1;
|
||||
uint8_t reserved2: 1;
|
||||
bool fast_b2b_capable: 1;
|
||||
bool master_data_parity_error: 1;
|
||||
uint8_t devsel_timing: 2;
|
||||
bool signaled_target_abort: 1;
|
||||
bool received_target_abort: 1;
|
||||
bool received_master_abort: 1;
|
||||
bool signaled_system_error: 1;
|
||||
bool detected_parity_error: 1;
|
||||
} packed status;
|
||||
} pci_status_register_t;
|
||||
|
||||
void pci_print_info();
|
||||
|
||||
void pci_dump_caps();
|
||||
|
||||
uint32_t pci_register_driver(const pci_driver *pci_driver);
|
||||
|
||||
void pci_sort_drivers();
|
||||
|
||||
@@ -70,13 +70,29 @@ int print_char(char character, int col, int row, char attributes) {
|
||||
offset = get_cursor_offset();
|
||||
}
|
||||
|
||||
if (character == '\n') {
|
||||
row = get_offset_row(offset);
|
||||
offset = get_offset(0, row + 1);
|
||||
} else {
|
||||
_vga_character_memory[offset] = character;
|
||||
_vga_character_memory[offset + 1] = attributes;
|
||||
offset += 2;
|
||||
switch (character) {
|
||||
case '\n':
|
||||
row = get_offset_row(offset);
|
||||
offset = get_offset(0, row + 1);
|
||||
break;
|
||||
case '\t':
|
||||
col = (col + 4) & (~0b11);
|
||||
if (col > VGA_COL_MAX) {
|
||||
row = get_offset_row(offset);
|
||||
offset = get_offset(0, row + 1);
|
||||
} else {
|
||||
offset = get_offset(col, row);
|
||||
}
|
||||
break;
|
||||
case '\r':
|
||||
row = get_offset_row(offset);
|
||||
offset = get_offset(0, row);
|
||||
break;
|
||||
default:
|
||||
_vga_character_memory[offset] = character;
|
||||
_vga_character_memory[offset + 1] = attributes;
|
||||
offset += 2;
|
||||
break;
|
||||
}
|
||||
|
||||
if (offset >= (VGA_COL_MAX * 2 * VGA_ROW_MAX)) {
|
||||
|
||||
Reference in New Issue
Block a user