iomap.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * linux/arch/arm/mm/iomap.c
  3. *
  4. * Map IO port and PCI memory spaces so that {read,write}[bwl] can
  5. * be used to access this memory.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/pci.h>
  9. #include <linux/ioport.h>
  10. #include <asm/io.h>
  11. #ifdef __io
  12. void __iomem *ioport_map(unsigned long port, unsigned int nr)
  13. {
  14. return __io(port);
  15. }
  16. EXPORT_SYMBOL(ioport_map);
  17. void ioport_unmap(void __iomem *addr)
  18. {
  19. }
  20. EXPORT_SYMBOL(ioport_unmap);
  21. #endif
  22. #ifdef CONFIG_PCI
  23. void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
  24. {
  25. unsigned long start = pci_resource_start(dev, bar);
  26. unsigned long len = pci_resource_len(dev, bar);
  27. unsigned long flags = pci_resource_flags(dev, bar);
  28. if (!len || !start)
  29. return NULL;
  30. if (maxlen && len > maxlen)
  31. len = maxlen;
  32. if (flags & IORESOURCE_IO)
  33. return ioport_map(start, len);
  34. if (flags & IORESOURCE_MEM) {
  35. if (flags & IORESOURCE_CACHEABLE)
  36. return ioremap(start, len);
  37. return ioremap_nocache(start, len);
  38. }
  39. return NULL;
  40. }
  41. EXPORT_SYMBOL(pci_iomap);
  42. void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
  43. {
  44. if ((unsigned long)addr >= VMALLOC_START &&
  45. (unsigned long)addr < VMALLOC_END)
  46. iounmap(addr);
  47. }
  48. EXPORT_SYMBOL(pci_iounmap);
  49. #endif