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

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

    if (pos >= 4096)
        return 0;

    shift = 8*(pos % 4);
    pos &= ~3;

    if (pcibus_conf_read(d->access->fd, d->bus, d->dev, d->func, pos, &val) < 0)
        d->access->error("nbsd_read: pci_bus_conf_read() failed");

    switch (len)
    {
    case 1:
        *buf = val >> shift;
        break;
    case 2:
        *(u16*)buf = cpu_to_le16(val >> shift);
        break;
    case 4:
        *(u32*)buf = cpu_to_le32(val);
        break;
    }
    return 1;
}
Example #2
0
static int
obsd_read(struct pci_dev *d, int pos, byte *buf, int len)
{
  struct pci_io pi;
  union {
	  u_int32_t u32;
	  u_int16_t u16[2];
	  u_int8_t u8[4];
  } u;

  if (!(len == 1 || len == 2 || len == 4))
    {
      return pci_generic_block_read(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 - (pos % 4);
  pi.pi_width = 4;

  if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0) {
	  if (errno == ENXIO) {
		  pi.pi_data = 0xffffffff;
	  } else {
		  d->access->error("obsd_read: ioctl(PCIOCREAD) failed");
	  }
  }
  u.u32 = pi.pi_data;

  switch (len)
    {
    case 1:
      buf[0] = (u8) u.u8[pos % 4];
      break;
    case 2:
      ((u16 *) buf)[0] = letoh16(u.u16[(pos % 4) / 2]);
      break;
    case 4:
      ((u32 *) buf)[0] = (u32) letoh32(pi.pi_data);
      break;
    }
  return 1;
}
static int
fbsd_read(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_read(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;

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

  switch (len)
    {
    case 1:
      buf[0] = (u8) pi.pi_data;
      break;
    case 2:
      ((u16 *) buf)[0] = cpu_to_le16((u16) pi.pi_data);
      break;
    case 4:
      ((u32 *) buf)[0] = cpu_to_le32((u32) pi.pi_data);
      break;
    }
  return 1;
}
Example #4
0
static int
fbsd_read(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_read(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;

  if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0)
    d->access->error("fbsd_read: ioctl(PCIOCREAD) failed");

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