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 __FreeBSD_version < 500000
23 # include <pci/pcivar.h>
25 # include <dev/pci/pcivar.h>
28 #if __FreeBSD_version < 430000
29 # include <pci/pci_ioctl.h>
31 # include <sys/pciio.h>
37 fbsd_config(struct pci_access *a)
39 a->method_params[PCI_ACCESS_FBSD_DEVICE] = PCI_PATH_FBSD_DEVICE;
43 fbsd_detect(struct pci_access *a)
45 char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE];
47 if (access(name, R_OK))
49 a->warning("Cannot open %s", name);
52 a->debug("...using %s", name);
57 fbsd_init(struct pci_access *a)
59 char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE];
61 a->fd = open(name, O_RDWR, 0);
64 a->error("fbsd_init: %s open failed", name);
69 fbsd_cleanup(struct pci_access *a)
75 fbsd_read(struct pci_dev *d, int pos, byte *buf, int len)
79 if (!(len == 1 || len == 2 || len == 4))
81 return pci_generic_block_read(d, pos, buf, len);
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)
95 d->access->error("fbsd_read: ioctl(PCIOCREAD) failed");
100 buf[0] = (u8) pi.pi_data;
103 ((u16 *) buf)[0] = (u16) pi.pi_data;
106 ((u32 *) buf)[0] = (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))
119 return pci_generic_block_write(d, pos, buf, len);
125 pi.pi_sel.pc_bus = d->bus;
126 pi.pi_sel.pc_dev = d->dev;
127 pi.pi_sel.pc_func = d->func;
138 pi.pi_data = ((u16 *) buf)[0];
141 pi.pi_data = ((u32 *) buf)[0];
145 if (ioctl(d->access->fd, PCIOCWRITE, &pi) < 0)
147 d->access->error("fbsd_write: ioctl(PCIOCWRITE) failed");
153 struct pci_methods pm_fbsd_device = {
160 pci_generic_fill_info,
164 NULL /* dev_cleanup */