2 * The PCI Library -- FreeBSD /dev/pci access
4 * Copyright (c) 1999 Jari Kirma <kirma@cs.hut.fi>
5 * Updated in 2003 by Samy Al Bahra <samy@kerneled.com>
7 * Can be freely distributed and used under the terms of the GNU GPL.
15 #include <osreldate.h>
18 #ifdef __FreeBSD_kernel_version
19 # ifndef __FreeBSD_version
20 # define __FreeBSD_version __FreeBSD_kernel_version
24 #if __FreeBSD_version < 430000 && !defined(__DragonFly__)
25 # include <pci/pcivar.h>
26 # include <pci/pci_ioctl.h>
28 # include <sys/pciio.h>
34 fbsd_config(struct pci_access *a)
36 pci_define_param(a, "fbsd.path", PCI_PATH_FBSD_DEVICE, "Path to the FreeBSD PCI device");
40 fbsd_detect(struct pci_access *a)
42 char *name = pci_get_param(a, "fbsd.path");
44 if (access(name, R_OK))
46 a->warning("Cannot open %s", name);
49 a->debug("...using %s", name);
54 fbsd_init(struct pci_access *a)
56 char *name = pci_get_param(a, "fbsd.path");
58 a->fd = open(name, O_RDWR, 0);
60 a->error("fbsd_init: %s open failed", name);
64 fbsd_cleanup(struct pci_access *a)
70 fbsd_read(struct pci_dev *d, int pos, byte *buf, int len)
74 if (!(len == 1 || len == 2 || len == 4))
75 return pci_generic_block_read(d, pos, buf, len);
80 #if __FreeBSD_version >= 700053
81 pi.pi_sel.pc_domain = d->domain;
83 pi.pi_sel.pc_bus = d->bus;
84 pi.pi_sel.pc_dev = d->dev;
85 pi.pi_sel.pc_func = d->func;
90 if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0)
94 d->access->error("fbsd_read: ioctl(PCIOCREAD) failed: %s", strerror(errno));
100 buf[0] = (u8) pi.pi_data;
103 ((u16 *) buf)[0] = cpu_to_le16((u16) pi.pi_data);
106 ((u32 *) buf)[0] = cpu_to_le32((u32) pi.pi_data);
113 fbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
117 if (!(len == 1 || len == 2 || len == 4))
118 return pci_generic_block_write(d, pos, buf, len);
123 #if __FreeBSD_version >= 700053
124 pi.pi_sel.pc_domain = d->domain;
126 pi.pi_sel.pc_bus = d->bus;
127 pi.pi_sel.pc_dev = d->dev;
128 pi.pi_sel.pc_func = d->func;
139 pi.pi_data = le16_to_cpu(((u16 *) buf)[0]);
142 pi.pi_data = le32_to_cpu(((u32 *) buf)[0]);
146 if (ioctl(d->access->fd, PCIOCWRITE, &pi) < 0)
150 d->access->error("fbsd_write: ioctl(PCIOCWRITE) failed: %s", strerror(errno));
156 struct pci_methods pm_fbsd_device = {
158 "FreeBSD /dev/pci device",
164 pci_generic_fill_info,
168 NULL /* dev_cleanup */