pci_iomap.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Implement the default iomap interfaces
  3. *
  4. * (C) Copyright 2004 Linus Torvalds
  5. */
  6. #include <linux/pci.h>
  7. #include <linux/io.h>
  8. #include <linux/export.h>
  9. #ifdef CONFIG_PCI
  10. /**
  11. * pci_iomap - create a virtual mapping cookie for a PCI BAR
  12. * @dev: PCI device that owns the BAR
  13. * @bar: BAR number
  14. * @maxlen: length of the memory to map
  15. *
  16. * Using this function you will get a __iomem address to your device BAR.
  17. * You can access it using ioread*() and iowrite*(). These functions hide
  18. * the details if this is a MMIO or PIO address space and will just do what
  19. * you expect from them in the correct way.
  20. *
  21. * @maxlen specifies the maximum length to map. If you want to get access to
  22. * the complete BAR without checking for its length first, pass %0 here.
  23. * */
  24. void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
  25. {
  26. resource_size_t start = pci_resource_start(dev, bar);
  27. resource_size_t len = pci_resource_len(dev, bar);
  28. unsigned long flags = pci_resource_flags(dev, bar);
  29. if (!len || !start)
  30. return NULL;
  31. if (maxlen && len > maxlen)
  32. len = maxlen;
  33. if (flags & IORESOURCE_IO)
  34. return __pci_ioport_map(dev, start, len);
  35. if (flags & IORESOURCE_MEM) {
  36. if (flags & IORESOURCE_CACHEABLE)
  37. return ioremap(start, len);
  38. return ioremap_nocache(start, len);
  39. }
  40. /* What? */
  41. return NULL;
  42. }
  43. EXPORT_SYMBOL(pci_iomap);
  44. #endif /* CONFIG_PCI */