47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#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);
|
|
}
|