2 * The PCI Library -- FreeBSD /dev/pci access
4 * Copyright (c) 1999 Jari Kirma <kirma@cs.hut.fi>
6 * Can be freely distributed and used under the terms of the GNU GPL.
10 * Read functionality of this driver is briefly tested, and seems
11 * to supply basic information correctly, but I promise no more.
18 #include <pci/pcivar.h>
19 #include <pci/pci_ioctl.h>
24 fbsd_config(struct pci_access *a)
26 a->method_params[PCI_ACCESS_FBSD_DEVICE] = PATH_FBSD_DEVICE;
30 fbsd_detect(struct pci_access *a)
32 char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE];
34 if (access(name, R_OK))
36 a->warning("Cannot open %s", name);
39 a->debug("...using %s", name);
44 fbsd_init(struct pci_access *a)
46 char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE];
48 a->fd = open(name, O_RDWR, 0);
51 a->error("fbsd_init: %s open failed", name);
56 fbsd_cleanup(struct pci_access *a)
62 fbsd_read(struct pci_dev *d, int pos, byte *buf, int len)
66 if (!(len == 1 || len == 2 || len == 4))
68 return pci_generic_block_read(d, pos, buf, len);
71 pi.pi_sel.pc_bus = d->bus;
72 pi.pi_sel.pc_dev = d->dev;
73 pi.pi_sel.pc_func = d->func;
78 if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0)
79 d->access->error("fbsd_read: ioctl(PCIOCREAD) failed");
84 buf[0] = (u8) pi.pi_data;
87 ((u16 *) buf)[0] = (u16) pi.pi_data;
90 ((u32 *) buf)[0] = (u32) pi.pi_data;
97 fbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
101 if (!(len == 1 || len == 2 || len == 4))
103 return pci_generic_block_write(d, pos, buf, len);
106 pi.pi_sel.pc_bus = d->bus;
107 pi.pi_sel.pc_dev = d->dev;
108 pi.pi_sel.pc_func = d->func;
119 pi.pi_data = ((u16 *) buf)[0];
122 pi.pi_data = ((u32 *) buf)[0];
126 if (ioctl(d->access->fd, PCIOCWRITE, &pi) < 0)
128 d->access->error("fbsd_write: ioctl(PCIOCWRITE) failed");
134 struct pci_methods pm_fbsd_device = {
141 pci_generic_fill_info,
145 NULL /* dev_cleanup */