summaryrefslogtreecommitdiff
path: root/src/openbsd_pci.c
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@herrb.eu>2014-12-21 19:12:36 +0100
committerMatthieu Herrb <matthieu@herrb.eu>2014-12-21 19:12:36 +0100
commitfce41489a0b2977712b2bb793c119d31801bca2a (patch)
tree85bdcc8c431438fc6a54cd4a297db7dc71497dd7 /src/openbsd_pci.c
parentfc6e8150993d2832e6d2a6a78dd8949a56a40036 (diff)
parent9b1bf11c81881c9cc6e6145011cf229978f109f4 (diff)
Merge remote-tracking branch 'origin/master' into obsd
Diffstat (limited to 'src/openbsd_pci.c')
-rw-r--r--src/openbsd_pci.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/openbsd_pci.c b/src/openbsd_pci.c
index 5b24a22..1e7e13f 100644
--- a/src/openbsd_pci.c
+++ b/src/openbsd_pci.c
@@ -81,6 +81,29 @@ pci_write(int domain, int bus, int dev, int func, uint32_t reg, uint32_t val)
return ioctl(pcifd[domain], PCIOCWRITE, &io);
}
+static int
+pci_readmask(int domain, int bus, int dev, int func, uint32_t reg,
+ uint32_t *val)
+{
+ struct pci_io io;
+ int err;
+
+ bzero(&io, sizeof(io));
+ io.pi_sel.pc_bus = bus;
+ io.pi_sel.pc_dev = dev;
+ io.pi_sel.pc_func = func;
+ io.pi_reg = reg;
+ io.pi_width = 4;
+
+ err = ioctl(pcifd[domain], PCIOCREADMASK, &io);
+ if (err)
+ return (err);
+
+ *val = io.pi_data;
+
+ return 0;
+}
+
/**
* Read a VGA ROM
*
@@ -328,11 +351,9 @@ pci_device_openbsd_probe(struct pci_device *device)
return err;
/* Probe the size of the region. */
- err = pci_write(domain, bus, dev, func, bar, ~0);
+ err = pci_readmask(domain, bus, dev, func, bar, &size);
if (err)
return err;
- pci_read(domain, bus, dev, func, bar, &size);
- pci_write(domain, bus, dev, func, bar, reg);
if (PCI_MAPREG_TYPE(reg) == PCI_MAPREG_TYPE_IO) {
region->is_IO = 1;
@@ -360,11 +381,9 @@ pci_device_openbsd_probe(struct pci_device *device)
return err;
reg64 |= (uint64_t)reg << 32;
- err = pci_write(domain, bus, dev, func, bar, ~0);
+ err = pci_readmask(domain, bus, dev, func, bar, &size);
if (err)
return err;
- pci_read(domain, bus, dev, func, bar, &size);
- pci_write(domain, bus, dev, func, bar, reg64 >> 32);
size64 |= (uint64_t)size << 32;
region->base_addr = PCI_MAPREG_MEM64_ADDR(reg64);