[Zion][Yellowstone] First pass at adding PCI ioport access.

This commit is contained in:
Drew Galbraith 2025-05-07 01:44:09 -07:00
parent f2c2cff98a
commit b677633248
16 changed files with 337 additions and 199 deletions

46
zion/object/pci_port.cpp Normal file
View file

@ -0,0 +1,46 @@
#include "object/pci_port.h"
#include "common/port.h"
namespace {
const uint16_t PCI_ADDR_PORT = 0xCF8;
const uint16_t PCI_DATA_PORT = 0xCFC;
uint32_t AddressOf(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) {
uint32_t lbus = (uint32_t)bus;
uint32_t lslot = (uint32_t)slot;
uint32_t lfunc = (uint32_t)func;
return (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) |
(offset & 0xFC) | ((uint32_t)0x80000000));
}
uint32_t PciReadAtOffset(uint8_t bus, uint8_t slot, uint8_t func,
uint8_t offset) {
uint32_t address = AddressOf(bus, slot, func, offset);
outl(PCI_ADDR_PORT, address);
return inl(PCI_DATA_PORT);
}
void PciWriteAtOffset(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset,
uint32_t word) {
uint32_t address = AddressOf(bus, slot, func, offset);
outl(PCI_ADDR_PORT, address);
outl(PCI_DATA_PORT, word);
}
} // namespace
uint32_t PciPort::ReadAtOffset(uint8_t bus, uint8_t slot, uint8_t func,
uint8_t offset) {
return PciReadAtOffset(bus, slot, func, offset);
}
uint32_t PciPortBound::Read(uint8_t offset) {
return PciReadAtOffset(bus_, slot_, func_, offset);
}
void PciPortBound::Write(uint8_t offset, uint32_t data) {
PciWriteAtOffset(bus_, slot_, func_, offset, data);
}