X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fnbsd-libpci.c;h=2d24c4cee69d96c92b421c126999adf1bede471b;hb=25cc4350661290538bdc0eb9932600309fd603f3;hp=e1bebd7d60a056485b4d99e2ec20d19c33ff315d;hpb=130090bd661f7c575d6751800daacabcb0a0baf3;p=pciutils.git diff --git a/lib/nbsd-libpci.c b/lib/nbsd-libpci.c index e1bebd7..2d24c4c 100644 --- a/lib/nbsd-libpci.c +++ b/lib/nbsd-libpci.c @@ -25,19 +25,22 @@ static void nbsd_config(struct pci_access *a) { - a->method_params[PCI_ACCESS_NBSD_LIBPCI] = PATH_NBSD_DEVICE; + pci_define_param(a, "nbsd.path", PCI_PATH_NBSD_DEVICE, "Path to the NetBSD PCI device"); } static int nbsd_detect(struct pci_access *a) { - char *name = a->method_params[PCI_ACCESS_NBSD_LIBPCI]; + char *name = pci_get_param(a, "nbsd.path"); if (access(name, R_OK)) { a->warning("Cannot open %s", name); return 0; } + + if (!access(name, W_OK)) + a->writeable = O_RDWR; a->debug("...using %s", name); return 1; } @@ -45,9 +48,10 @@ nbsd_detect(struct pci_access *a) static void nbsd_init(struct pci_access *a) { - char *name = a->method_params[PCI_ACCESS_NBSD_LIBPCI]; + char *name = pci_get_param(a, "nbsd.path"); + int mode = a->writeable ? O_RDWR : O_RDONLY; - a->fd = open(name, O_RDWR, 0); + a->fd = open(name, mode, 0); if (a->fd < 0) a->error("nbsd_init: %s open failed", name); } @@ -67,9 +71,12 @@ nbsd_read(struct pci_dev *d, int pos, byte *buf, int len) if (!(len == 1 || len == 2 || len == 4)) return pci_generic_block_read(d, pos, buf, len); + if (pos >= 256) + return 0; + shift = 8*(pos % 4); pos &= ~3; - + if (pcibus_conf_read(d->access->fd, d->bus, d->dev, d->func, pos, &val) < 0) d->access->error("nbsd_read: pci_bus_conf_read() failed"); @@ -97,6 +104,9 @@ nbsd_write(struct pci_dev *d, int pos, byte *buf, int len) if (!(len == 1 || len == 2 || len == 4)) return pci_generic_block_write(d, pos, buf, len); + if (pos >= 256) + return 0; + /* * BEWARE: NetBSD seems to support only 32-bit access, so we have * to emulate byte and word writes by read-modify-write, possibly @@ -104,7 +114,7 @@ nbsd_write(struct pci_dev *d, int pos, byte *buf, int len) */ shift = 8*(pos % 4); - pos &= 3; + pos &= ~3; if (len != 4) { if (pcibus_conf_read(d->access->fd, d->bus, d->dev, d->func, pos, &val) < 0) @@ -114,16 +124,16 @@ nbsd_write(struct pci_dev *d, int pos, byte *buf, int len) switch (len) { case 1: - val = (val & ~(0xff << shift)) | buf[0]; + val = (val & ~(0xff << shift)) | (buf[0] << shift); break; case 2: - val = (val & ~(0xffff << shift)) | le16_to_cpu(*(u16*)buf); + val = (val & ~(0xffff << shift)) | (le16_to_cpu(*(u16*)buf) << shift); break; case 4: val = le32_to_cpu(*(u32*)buf); break; } - + if (pcibus_conf_write(d->access->fd, d->bus, d->dev, d->func, pos, val) < 0) d->access->error("nbsd_write: pci_bus_conf_write() failed"); @@ -131,7 +141,8 @@ nbsd_write(struct pci_dev *d, int pos, byte *buf, int len) } struct pci_methods pm_nbsd_libpci = { - "NetBSD-libpci", + "nbsd-libpci", + "NetBSD libpci", nbsd_config, nbsd_detect, nbsd_init,