some work with PCI, updated my TODO

This commit is contained in:
2025-06-09 17:02:46 -04:00
parent a776376403
commit f1515ad7b5
7 changed files with 63 additions and 31 deletions

View File

@ -3,6 +3,12 @@
#include <stdio.h>
/**
* None of this is working. I'm assuming that QEMU (and bochs) are using pcie purely memory mapped, without legacy PCI support
*
* so we'll need to setup ACPI first :)
*/
uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset)
{
uint32_t address;
@ -15,20 +21,22 @@ uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t o
address = (uint32_t) ((lbus << 16) | (lslot << 11) |
(lfunc << 8) | (offset & 0xFC) | ((uint32_t) 0x80000000));
printf("%b\n", address);
outb_32(PCI_CONFIG_ADDRESS, address);
tmp = (uint16_t)((inb(PCI_CONFIG_DATA) >> ((offset & 2) * 8)) * 0xFFFF);
tmp = (uint16_t)((inb(PCI_CONFIG_DATA) >> ((offset & 2) * 8)) & 0xFFFF);
return tmp;
}
uint16_t pci_check_vendor(uint8_t bus, uint8_t slot)
uint16_t pci_check_vendor(uint8_t bus, uint8_t slot, uint8_t func)
{
uint16_t vendor, device;
if ((vendor = pci_config_read_word(bus, slot, 0, 0)) != 0xFFFF) {
device = pci_config_read_word(bus, slot, 0, 2);
printf("Device: %d, Vendor: %d\n", device, vendor);
if ((vendor = pci_config_read_word(bus, slot, func, 0)) != 0xFFFF) {
device = pci_config_read_word(bus, slot, func, 2);
// we'll do something here, store all the pcis in memory or something
device++;
}
return vendor;
}

View File

@ -8,6 +8,9 @@
uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset);
uint16_t pci_check_vendor(uint8_t bus, uint8_t slot);
uint16_t pci_check_vendor(uint8_t bus, uint8_t slot, uint8_t func);
void check_all_busses(void);
#endif

View File

@ -10,7 +10,7 @@
#include <kernel/x86/keyb.h>
#include <kernel/x86/pit.h>
#include <kernel/x86/pit.h>
#include <kernel/x86/pci.h>
void kmain(void)
@ -31,7 +31,8 @@ void kmain(void)
init_pit(0x36, PIT_CHANNEL_0, 0);
printf("%f\n", get_time_from_divisor(10));
printf("%d\n", pci_config_read_word(0, 1, 1, 6));
printf("Entering loop...\n");
while (1) {