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.
13 #include <osreldate.h>
16 #ifdef __FreeBSD_kernel_version
17 # ifndef __FreeBSD_version
18 # define __FreeBSD_version __FreeBSD_kernel_version
22 #if defined(__DragonFly__)
23 # include <bus/pci/pcivar.h>
24 #elif __FreeBSD_version < 500000
25 # include <pci/pcivar.h>
27 # include <dev/pci/pcivar.h>
30 #if __FreeBSD_version < 430000 && !defined(__DragonFly__)
31 # include <pci/pci_ioctl.h>
33 # include <sys/pciio.h>
39 fbsd_config(struct pci_access *a)
41 a->method_params[PCI_ACCESS_FBSD_DEVICE] = PCI_PATH_FBSD_DEVICE;
45 fbsd_detect(struct pci_access *a)
47 char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE];
49 if (access(name, R_OK))
51 a->warning("Cannot open %s", name);
54 a->debug("...using %s", name);
59 fbsd_init(struct pci_access *a)
61 char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE];
63 a->fd = open(name, O_RDWR, 0);
66 a->error("fbsd_init: %s open failed", name);
71 fbsd_cleanup(struct pci_access *a)
77 fbsd_read(struct pci_dev *d, int pos, byte *buf, int len)
81 if (!(len == 1 || len == 2 || len == 4))
83 return pci_generic_block_read(d, pos, buf, len);
89 pi.pi_sel.pc_bus = d->bus;
90 pi.pi_sel.pc_dev = d->dev;
91 pi.pi_sel.pc_func = d->func;
96 if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0)
97 d->access->error("fbsd_read: ioctl(PCIOCREAD) failed");
102 buf[0] = (u8) pi.pi_data;
105 ((u16 *) buf)[0] = (u16) pi.pi_data;
108 ((u32 *) buf)[0] = (u32) pi.pi_data;
115 fbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
119 if (!(len == 1 || len == 2 || len == 4))
121 return pci_generic_block_write(d, pos, buf, len);
127 pi.pi_sel.pc_bus = d->bus;
128 pi.pi_sel.pc_dev = d->dev;
129 pi.pi_sel.pc_func = d->func;
140 pi.pi_data = ((u16 *) buf)[0];
143 pi.pi_data = ((u32 *) buf)[0];
147 if (ioctl(d->access->fd, PCIOCWRITE, &pi) < 0)
149 d->access->error("fbsd_write: ioctl(PCIOCWRITE) failed");
155 struct pci_methods pm_fbsd_device = {
162 pci_generic_fill_info,
166 NULL /* dev_cleanup */