kv2: initialize memory manager, early pci devices

Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
Michael Shaw 2026-05-12 02:59:37 -04:00
commit a252a3f8e9
58 changed files with 1270 additions and 505 deletions

View file

@ -3,13 +3,14 @@
#include <kernel/mem.h>
#include <kernel/slab.h>
#include <drivers/pci.h>
#include <drivers/ahci.h>
#include <lib/string.h>
#include <lib/stdio.h>
#include <drivers/ahci.h>
static uint8_t sata_device_count = 0;
static struct sata_device sata_devices[32] = { 0 };
static struct sata_device sata_devices[32] = {0};
static paddr_t ahci_pbase = 0;
static vaddr_t ahci_vbase = 0;
@ -70,15 +71,17 @@ static void ahci_rebase(hbaport_t *port, int n)
cmdheader[i].prdt_len = 8;
cmdheader[i].cmd_table_base = (ahci_pbase) + (n << 13) + (40 << 10) + (i << 8);
void *ctba = (void *)((uintptr_t)cmdheader[i].cmd_table_base | hhdm_start);
void *ctba = (void *)(TO_VIRT((paddr_t)cmdheader[i].cmd_table_base));
memset(ctba, 0, 256);
}
start_cmd(port);
}
static void ahci_probe_ports(struct pci_device *dev, hbamem_t *abar)
static void ahci_probe_ports(struct ahci_host *host)
{
struct pci_device *dev = host->device;
hbamem_t *abar = host->abar;
uint32_t pi = abar->pi;
for (int i = 0; i < 32; i++) {
if (pi & 1) {
@ -86,13 +89,12 @@ static void ahci_probe_ports(struct pci_device *dev, hbamem_t *abar)
if (type == AHCI_DEV_SATA) {
struct sata_device *sdev = &sata_devices[sata_device_count];
sdev->port = i;
sdev->controller = dev;
sdev->abar = abar;
sdev->host = host;
/* char *name = kzalloc(16, ALLOC_KERN);
char *name = kzalloc(16, ALLOC_KERN);
name[15] = 0;
snprintf(name, "ahci%d", 15, sata_device_count);*/
snprintf(name, 15, "ahci%d", sata_device_count);
size_t sector_count = ((size_t)abar->ports[i].ssts) << 32 | abar->ports[i].ssts;
sdev->sector_count = sector_count;
@ -100,7 +102,7 @@ static void ahci_probe_ports(struct pci_device *dev, hbamem_t *abar)
sdev->sector_size = 512;
/* bdev = block_register(name, &ahci_block_ops, sdev, sector_count, sdev->sector_size);
block_gpt_init(bdev);*/
block_gpt_init(bdev); */
ahci_rebase(&abar->ports[i], i);
sata_device_count++;
@ -132,7 +134,7 @@ static int cmdslot(hbaport_t *port)
int ahci_access_sectors(struct sata_device *dev, paddr_t lba, uint16_t count, paddr_t buf, bool write)
{
hbaport_t *port = &dev->abar->ports[dev->port];
hbaport_t *port = &dev->host->abar->ports[dev->port];
/* clear pending interrupt */
port->is = (uint32_t)-1;
@ -210,6 +212,20 @@ int ahci_access_sectors(struct sata_device *dev, paddr_t lba, uint16_t count, pa
return true;
}
void ahci_init()
void ahci_init_device(struct pci_device *device)
{
}
void ahci_init()
{
list_t dev_list;
list_create(&dev_list);
size_t n = pci_find_device(0x0001, 0x0006, &dev_list);
list_item_t *item = dev_list.head;
while (item) {
ahci_init_device(item->ptr);
item = item->next;
}
}