Example #1
0
static int
nbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
{
    pcireg_t val = 0;
    int shift;

    if (!(len == 1 || len == 2 || len == 4))
        return pci_generic_block_write(d, pos, buf, len);

    if (pos >= 256)
        return 0;

    /*
     *  BEWARE: NetBSD seems to support only 32-bit access, so we have
     *  to emulate byte and word writes by read-modify-write, possibly
     *  causing troubles.
     */

    shift = 8*(pos % 4);
    pos &= ~3;
    if (len != 4)
    {
        if (pcibus_conf_read(d->access->fd, d->bus, d->dev, d->func, pos, &val) < 0)
            d->access->error("nbsd_write: pci_bus_conf_read() failed");
    }

    switch (len)
    {
    case 1:
        val = (val & ~(0xff << shift)) | (buf[0] << shift);
        break;
    case 2:
        val = (val & ~(0xffff << shift)) | (le16_to_cpu(*(u16*)buf) << shift);
        break;
    case 4:
        val = le32_to_cpu(*(u32*)buf);
        break;
    }

    if (pcibus_conf_write(d->access->fd, d->bus, d->dev, d->func, pos, val) < 0)
        d->access->error("nbsd_write: pci_bus_conf_write() failed");

    return 1;
}
static int
fbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
{
  struct pci_io pi;

  if (!(len == 1 || len == 2 || len == 4))
    return pci_generic_block_write(d, pos, buf, len);

  if (pos >= 256)
    return 0;

#if __FreeBSD_version >= 700053
  pi.pi_sel.pc_domain = d->domain;
#endif
  pi.pi_sel.pc_bus = d->bus;
  pi.pi_sel.pc_dev = d->dev;
  pi.pi_sel.pc_func = d->func;

  pi.pi_reg = pos;
  pi.pi_width = len;

  switch (len)
    {
    case 1:
      pi.pi_data = buf[0];
      break;
    case 2:
      pi.pi_data = le16_to_cpu(((u16 *) buf)[0]);
      break;
    case 4:
      pi.pi_data = le32_to_cpu(((u32 *) buf)[0]);
      break;
    }

  if (ioctl(d->access->fd, PCIOCWRITE, &pi) < 0)
    {
      if (errno == ENODEV)
	return 0;
      d->access->error("fbsd_write: ioctl(PCIOCWRITE) failed: %s", strerror(errno));
    }

  return 1;
}
Example #3
0
static int
obsd_write(struct pci_dev *d, int pos, byte *buf, int len)
{
  struct pci_io pi;

  if (!(len == 1 || len == 2 || len == 4))
    {
      return pci_generic_block_write(d, pos, buf, len);
    }

  if (pos >= 256)
    return 0;

  pi.pi_sel.pc_bus = d->bus;
  pi.pi_sel.pc_dev = d->dev;
  pi.pi_sel.pc_func = d->func;

  pi.pi_reg = pos;
  pi.pi_width = len;

  switch (len)
    {
    case 1:
      pi.pi_data = buf[0];
      break;
    case 2:
      pi.pi_data = ((u16 *) buf)[0];
      break;
    case 4:
      pi.pi_data = ((u32 *) buf)[0];
      break;
    }

  if (ioctl(d->access->fd, PCIOCWRITE, &pi) < 0)
    {
      d->access->error("obsd_write: ioctl(PCIOCWRITE) failed");
    }

  return 1;
}