X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffbsd-device.c;h=742c6419f54efa1dbdb1b64057c3402e40345624;hb=2f4211843f4f68c2a8a92155c24ac72d5799379b;hp=46fa7a2d15719d6a0b31f3fb7d481d1dba763fa9;hpb=94db5c82212761573cc656df77c727001f554591;p=pciutils.git diff --git a/lib/fbsd-device.c b/lib/fbsd-device.c index 46fa7a2..742c641 100644 --- a/lib/fbsd-device.c +++ b/lib/fbsd-device.c @@ -7,7 +7,9 @@ * Can be freely distributed and used under the terms of the GNU GPL. */ +#include #include +#include #include #include #include @@ -19,13 +21,8 @@ # endif #endif -#if __FreeBSD_version < 500000 +#if __FreeBSD_version < 430000 && !defined(__DragonFly__) # include -#else -# include -#endif - -#if __FreeBSD_version < 430000 # include #else # include @@ -36,13 +33,13 @@ static void fbsd_config(struct pci_access *a) { - a->method_params[PCI_ACCESS_FBSD_DEVICE] = PCI_PATH_FBSD_DEVICE; + pci_define_param(a, "fbsd.path", PCI_PATH_FBSD_DEVICE, "Path to the FreeBSD PCI device"); } static int fbsd_detect(struct pci_access *a) { - char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE]; + char *name = pci_get_param(a, "fbsd.path"); if (access(name, R_OK)) { @@ -56,13 +53,11 @@ fbsd_detect(struct pci_access *a) static void fbsd_init(struct pci_access *a) { - char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE]; + char *name = pci_get_param(a, "fbsd.path"); a->fd = open(name, O_RDWR, 0); if (a->fd < 0) - { - a->error("fbsd_init: %s open failed", name); - } + a->error("fbsd_init: %s open failed", name); } static void @@ -77,13 +72,14 @@ fbsd_read(struct pci_dev *d, int pos, byte *buf, int len) struct pci_io pi; if (!(len == 1 || len == 2 || len == 4)) - { - return pci_generic_block_read(d, pos, buf, len); - } + return pci_generic_block_read(d, pos, buf, len); if (pos >= 256) return 0; +#if __FreeBSD_version >= 700053 + pi.pi_sel.pc_domain = d->domain; +#endif pi.pi_sel.pc_bus = d->bus; pi.pi_sel.pc_dev = d->dev; pi.pi_sel.pc_func = d->func; @@ -92,7 +88,11 @@ fbsd_read(struct pci_dev *d, int pos, byte *buf, int len) pi.pi_width = len; if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0) - d->access->error("fbsd_read: ioctl(PCIOCREAD) failed"); + { + if (errno == ENODEV) + return 0; + d->access->error("fbsd_read: ioctl(PCIOCREAD) failed: %s", strerror(errno)); + } switch (len) { @@ -100,10 +100,10 @@ fbsd_read(struct pci_dev *d, int pos, byte *buf, int len) buf[0] = (u8) pi.pi_data; break; case 2: - ((u16 *) buf)[0] = (u16) pi.pi_data; + ((u16 *) buf)[0] = cpu_to_le16((u16) pi.pi_data); break; case 4: - ((u32 *) buf)[0] = (u32) pi.pi_data; + ((u32 *) buf)[0] = cpu_to_le32((u32) pi.pi_data); break; } return 1; @@ -115,13 +115,14 @@ fbsd_write(struct pci_dev *d, int pos, byte *buf, int len) struct pci_io pi; if (!(len == 1 || len == 2 || len == 4)) - { - return pci_generic_block_write(d, pos, buf, len); - } + return pci_generic_block_write(d, pos, buf, len); if (pos >= 256) return 0; +#if __FreeBSD_version >= 700053 + pi.pi_sel.pc_domain = d->domain; +#endif pi.pi_sel.pc_bus = d->bus; pi.pi_sel.pc_dev = d->dev; pi.pi_sel.pc_func = d->func; @@ -135,23 +136,26 @@ fbsd_write(struct pci_dev *d, int pos, byte *buf, int len) pi.pi_data = buf[0]; break; case 2: - pi.pi_data = ((u16 *) buf)[0]; + pi.pi_data = le16_to_cpu(((u16 *) buf)[0]); break; case 4: - pi.pi_data = ((u32 *) buf)[0]; + pi.pi_data = le32_to_cpu(((u32 *) buf)[0]); break; } if (ioctl(d->access->fd, PCIOCWRITE, &pi) < 0) { - d->access->error("fbsd_write: ioctl(PCIOCWRITE) failed"); + if (errno == ENODEV) + return 0; + d->access->error("fbsd_write: ioctl(PCIOCWRITE) failed: %s", strerror(errno)); } return 1; } struct pci_methods pm_fbsd_device = { - "FreeBSD-device", + "fbsd-device", + "FreeBSD /dev/pci device", fbsd_config, fbsd_detect, fbsd_init,