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 a->method_params[PCI_ACCESS_FBSD_DEVICE] = PCI_PATH_FBSD_DEVICE;
40 fbsd_detect(struct pci_access *a)
42 char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE];
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 = a->method_params[PCI_ACCESS_FBSD_DEVICE];
58 a->fd = open(name, O_RDWR, 0);
61 a->error("fbsd_init: %s open failed", name);
66 fbsd_cleanup(struct pci_access *a)
72 fbsd_read(struct pci_dev *d, int pos, byte *buf, int len)
76 if (!(len == 1 || len == 2 || len == 4))
78 return pci_generic_block_read(d, pos, buf, len);
84 #if __FreeBSD_version >= 700053
85 pi.pi_sel.pc_domain = d->domain;
87 pi.pi_sel.pc_bus = d->bus;
88 pi.pi_sel.pc_dev = d->dev;
89 pi.pi_sel.pc_func = d->func;
94 if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0)
100 d->access->error("fbsd_read: ioctl(PCIOCREAD) failed: %s", strerror(errno));
106 buf[0] = (u8) pi.pi_data;
109 ((u16 *) buf)[0] = cpu_to_le16((u16) pi.pi_data);
112 ((u32 *) buf)[0] = cpu_to_le32((u32) pi.pi_data);
119 fbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
123 if (!(len == 1 || len == 2 || len == 4))
125 return pci_generic_block_write(d, pos, buf, len);
131 #if __FreeBSD_version >= 700053
132 pi.pi_sel.pc_domain = d->domain;
134 pi.pi_sel.pc_bus = d->bus;
135 pi.pi_sel.pc_dev = d->dev;
136 pi.pi_sel.pc_func = d->func;
147 pi.pi_data = le16_to_cpu(((u16 *) buf)[0]);
150 pi.pi_data = le32_to_cpu(((u32 *) buf)[0]);
154 if (ioctl(d->access->fd, PCIOCWRITE, &pi) < 0)
160 d->access->error("fbsd_write: ioctl(PCIOCWRITE) failed: %s", strerror(errno));
166 struct pci_methods pm_fbsd_device = {
173 pci_generic_fill_info,
177 NULL /* dev_cleanup */