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>
15 #if __FreeBSD_version < 500000
16 # include <pci/pcivar.h>
18 # include <dev/pci/pcivar.h>
21 #if __FreeBSD_version < 430000
22 # include <pci/pci_ioctl.h>
24 # include <sys/pciio.h>
30 fbsd_config(struct pci_access *a)
32 a->method_params[PCI_ACCESS_FBSD_DEVICE] = PATH_FBSD_DEVICE;
36 fbsd_detect(struct pci_access *a)
38 char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE];
40 if (access(name, R_OK))
42 a->warning("Cannot open %s", name);
45 a->debug("...using %s", name);
50 fbsd_init(struct pci_access *a)
52 char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE];
54 a->fd = open(name, O_RDWR, 0);
57 a->error("fbsd_init: %s open failed", name);
62 fbsd_cleanup(struct pci_access *a)
68 fbsd_read(struct pci_dev *d, int pos, byte *buf, int len)
72 if (!(len == 1 || len == 2 || len == 4))
74 return pci_generic_block_read(d, pos, buf, len);
77 pi.pi_sel.pc_bus = d->bus;
78 pi.pi_sel.pc_dev = d->dev;
79 pi.pi_sel.pc_func = d->func;
84 if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0)
85 d->access->error("fbsd_read: ioctl(PCIOCREAD) failed");
90 buf[0] = (u8) pi.pi_data;
93 ((u16 *) buf)[0] = (u16) pi.pi_data;
96 ((u32 *) buf)[0] = (u32) pi.pi_data;
103 fbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
107 if (!(len == 1 || len == 2 || len == 4))
109 return pci_generic_block_write(d, pos, buf, len);
112 pi.pi_sel.pc_bus = d->bus;
113 pi.pi_sel.pc_dev = d->dev;
114 pi.pi_sel.pc_func = d->func;
125 pi.pi_data = ((u16 *) buf)[0];
128 pi.pi_data = ((u32 *) buf)[0];
132 if (ioctl(d->access->fd, PCIOCWRITE, &pi) < 0)
134 d->access->error("fbsd_write: ioctl(PCIOCWRITE) failed");
140 struct pci_methods pm_fbsd_device = {
147 pci_generic_fill_info,
151 NULL /* dev_cleanup */