diff options
author | Ian Moffett <ian@osmora.org> | 2024-03-28 19:49:47 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-28 19:49:47 -0400 |
commit | 4fc22f9295061d17e11828af625d9f92aabfb4a5 (patch) | |
tree | ab1c7e6381f6237d6bfa0ee0e52baaaeac859ced /sys/dev | |
parent | 41ab808cd0e4d6d7b80b6112198520adb3860e85 (diff) |
kernel: pci: Add pci_writel()
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/pci/pci.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index f681431..57133bf 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -74,6 +74,33 @@ pci_cam_read(const struct pci_device *dev, uint32_t offset) #endif } +/* + * Write to device's legacy PCI CAM space + * + * @dev: Device to write to. + * @offset: Offset to write at. + * + * XXX: Do not use directly! + */ +static void +pci_cam_write(const struct pci_device *dev, uint32_t offset, uint32_t value) +{ +#if defined(__x86_64__) + uint32_t address; + + address = __BIT(31) | + (offset & ~3) | + (dev->func << 8) | + (dev->slot << 11) | + (dev->bus << 16); + + outl(0xCF8, address); + outb(0xCFC, value); +#else + panic("Invalid arch (%s())\n", __func__); +#endif +} + static bool pci_device_exists(uint8_t bus, uint8_t slot, uint8_t func) { @@ -167,6 +194,24 @@ pci_readl(struct pci_device *dev, uint32_t offset) __builtin_unreachable(); } +/* + * Write to PCI(e) configuration space. + * + * @dev: Device to write to. + * @offset: Offset to write at. + */ +void +pci_writel(struct pci_device *dev, uint32_t offset, uint32_t val) +{ + if (access_method == PCI_ACCESS_CAM) { + pci_cam_write(dev, offset, val); + return; + } + + panic("Invalid access method (%s())\n", __func__); + __builtin_unreachable(); +} + struct pci_device * pci_get_device(struct pci_lookup lookup, uint16_t lookup_type) { |