Example #1
0
/* Compute the pixel position of a progress value */
static inline int get_bar_position( PROGRESS_INFO *infoPtr, LONG style,
                                    const RECT* rect, INT value )
{
    return MulDiv (value - infoPtr->MinVal, get_bar_size (style, rect),
                      infoPtr->MaxVal - infoPtr->MinVal);
}
Example #2
0
sbone_err_t sbone_dev_open_pcie
(sbone_dev_t* dev, int dom, int bus, int _dev, int fun)
{
  static const size_t nbar = sizeof(dev->bar_addrs) / sizeof(dev->bar_addrs[0]);
  int mem_fd;
  size_t i;
  struct pci_access* pci_access;
  struct pci_dev* pci_dev;
  int err = -1;

  /* zero device */

  for (i = 0; i < nbar; ++i) dev->bar_sizes[i] = 0;

  dev->nid = -1;

  /* find the pci device */

  pci_access = pci_alloc();
  if (pci_access == NULL) { PERROR(); goto on_error_0; }
  pci_init(pci_access);
  pci_scan_bus(pci_access);

  pci_dev = pci_get_dev(pci_access, dom, bus, _dev, fun);
  if (pci_dev == NULL) { PERROR(); goto on_error_1; }
  pci_fill_info(pci_dev, PCI_FILL_IDENT | PCI_FILL_BASES);

  /* map bars */

  mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
  if (mem_fd == -1) { PERROR(); goto on_error_2; }

  for (i = 0; i < nbar; ++i)
  {
#if 1 /* FIXME: pci_dev->size[i] not detected by pci_fill_info ... */
    if (pci_dev->base_addr[i] != 0)
      pci_dev->size[i] = get_bar_size(pci_access, pci_dev, i);
#endif /* FIXME */

    dev->bar_sizes[i] = pci_dev->size[i];
    if (dev->bar_sizes[i] == 0) continue ;

    dev->bar_addrs[i] = (uintptr_t)mmap
    (
     NULL, pci_dev->size[i],
     PROT_READ | PROT_WRITE,
     MAP_SHARED | MAP_NORESERVE,
     mem_fd,
     pci_dev->base_addr[i]
    );

    if (dev->bar_addrs[i] == (uintptr_t)MAP_FAILED)
    {
      size_t j;
      for (j = 0; j < i; ++j)
	munmap((void*)dev->bar_addrs[i], dev->bar_sizes[i]);
      PERROR();
      goto on_error_3;
    }
  }

  if ((dev->fd = open("/dev/sbone", O_RDWR)) == -1)
  {
    PERROR();
    goto on_error_3;
  }

  /* success */

  err = 0;

 on_error_3:
  close(mem_fd);
 on_error_2:
  pci_free_dev(pci_dev);
 on_error_1:
  pci_cleanup(pci_access);
 on_error_0:
  return err;

}