i am currently working on AHCI implementation. I use the codebase from "MonkOS" (https://github.com/beevik/MonkOS) and tried to implement AHCI based on the code from https://github.com/ethan4984/rock/blob/ ... ers/ahci.c
getting pci bar information does work but as soon as I start reading from that memory region I get a page fault.
Here is my AHCI_init code so far:
Code: Select all
void ahci_init(struct pci_device *device) {
switch(device->prog_if) {
case 0:
kprint("[AHCI] detected a vendor specific interface (get a new pc)\n");
return;
case 1:
kprint("[AHCI] detetced an AHCI 1.0 compatiable device\n");
break;
case 2:
kprint("[AHCI] detetced a serial storage bus\n");
return;
}
pci_become_bus_master(device);
struct pci_bar bar;
if(pci_get_bar(device, &bar, 5) == -1)
return;
pmap_add(PAGE_ALIGN_DOWN(bar.base), PAGE_SIZE, PMEMTYPE_UNCACHED); //<-- this might be wrong?
volatile struct GHC *GHC = (volatile struct GHC*)((size_t)bar.base);
for(int i = 0; i < 32; i++) {
if(GHC->pi & (1 << i)) {
volatile struct port_regs *regs = (volatile struct port_regs*)&GHC->port[i];
switch(regs->sig) {
case SATA_ATA:
kprintf("[AHCI] sata drive found on port %d\n", i);
init_sata_device(regs);
break;
case SATA_ATAPI:
kprintf("[AHCI] ATAPI drive found on port %d\n", i);
break;
case SATA_SEMB:
kprintf("[AHCI] enclosure management bridge found on port %d\n", i);
break;
case SATA_PM:
kprintf("[AHCI] port multipler found on port %d\n", i);
break;
}
}
}
}
Maybe I am misunderstanding the memory management in the codebase of "MonkOS"? Might someone lead me in the right direction?