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] = PCI_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);
80 pi.pi_sel.pc_bus = d->bus;
81 pi.pi_sel.pc_dev = d->dev;
82 pi.pi_sel.pc_func = d->func;
87 if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0)
88 d->access->error("fbsd_read: ioctl(PCIOCREAD) failed");
93 buf[0] = (u8) pi.pi_data;
96 ((u16 *) buf)[0] = (u16) pi.pi_data;
99 ((u32 *) buf)[0] = (u32) pi.pi_data;
106 fbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
110 if (!(len == 1 || len == 2 || len == 4))
112 return pci_generic_block_write(d, pos, buf, len);
118 pi.pi_sel.pc_bus = d->bus;
119 pi.pi_sel.pc_dev = d->dev;
120 pi.pi_sel.pc_func = d->func;
131 pi.pi_data = ((u16 *) buf)[0];
134 pi.pi_data = ((u32 *) buf)[0];
138 if (ioctl(d->access->fd, PCIOCWRITE, &pi) < 0)
140 d->access->error("fbsd_write: ioctl(PCIOCWRITE) failed");
146 struct pci_methods pm_fbsd_device = {
153 pci_generic_fill_info,
157 NULL /* dev_cleanup */