2 * The PCI Library -- NetBSD libpci access
3 * (based on FreeBSD /dev/pci access)
5 * Copyright (c) 1999 Jari Kirma <kirma@cs.hut.fi>
6 * Copyright (c) 2002 Quentin Garnier <cube@cubidou.net>
7 * Copyright (c) 2002 Martin Mares <mj@ucw.cz>
9 * Can be freely distributed and used under the terms of the GNU GPL.
13 * Read functionality of this driver is briefly tested, and seems
14 * to supply basic information correctly, but I promise no more.
26 nbsd_config(struct pci_access *a)
28 a->method_params[PCI_ACCESS_NBSD_LIBPCI] = PCI_PATH_NBSD_DEVICE;
32 nbsd_detect(struct pci_access *a)
34 char *name = a->method_params[PCI_ACCESS_NBSD_LIBPCI];
36 if (access(name, R_OK))
38 a->warning("Cannot open %s", name);
42 if (!access(name, W_OK))
44 a->writeable = O_RDWR;
46 a->debug("...using %s", name);
51 nbsd_init(struct pci_access *a)
53 char *name = a->method_params[PCI_ACCESS_NBSD_LIBPCI];
54 int mode = a->writeable ? O_RDWR : O_RDONLY;
56 a->fd = open(name, mode, 0);
58 a->error("nbsd_init: %s open failed", name);
62 nbsd_cleanup(struct pci_access *a)
68 nbsd_read(struct pci_dev *d, int pos, byte *buf, int len)
73 if (!(len == 1 || len == 2 || len == 4))
74 return pci_generic_block_read(d, pos, buf, len);
82 if (pcibus_conf_read(d->access->fd, d->bus, d->dev, d->func, pos, &val) < 0)
83 d->access->error("nbsd_read: pci_bus_conf_read() failed");
91 *(u16*)buf = cpu_to_le16(val >> shift);
94 *(u32*)buf = cpu_to_le32(val);
101 nbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
106 if (!(len == 1 || len == 2 || len == 4))
107 return pci_generic_block_write(d, pos, buf, len);
113 * BEWARE: NetBSD seems to support only 32-bit access, so we have
114 * to emulate byte and word writes by read-modify-write, possibly
122 if (pcibus_conf_read(d->access->fd, d->bus, d->dev, d->func, pos, &val) < 0)
123 d->access->error("nbsd_write: pci_bus_conf_read() failed");
129 val = (val & ~(0xff << shift)) | (buf[0] << shift);
132 val = (val & ~(0xffff << shift)) | (le16_to_cpu(*(u16*)buf) << shift);
135 val = le32_to_cpu(*(u32*)buf);
139 if (pcibus_conf_write(d->access->fd, d->bus, d->dev, d->func, pos, val) < 0)
140 d->access->error("nbsd_write: pci_bus_conf_write() failed");
145 struct pci_methods pm_nbsd_libpci = {
152 pci_generic_fill_info,
156 NULL /* dev_cleanup */