iomap.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * iomap.c, Memory Mapped I/O routines for MIPS architecture.
  3. *
  4. * This code is based on lib/iomap.c, by Linus Torvalds.
  5. *
  6. * Copyright (C) 2004-2005 Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/ioport.h>
  23. #include <linux/module.h>
  24. #include <linux/pci.h>
  25. #include <asm/io.h>
  26. void __iomem *ioport_map(unsigned long port, unsigned int nr)
  27. {
  28. unsigned long end;
  29. end = port + nr - 1UL;
  30. if (ioport_resource.start > port ||
  31. ioport_resource.end < end || port > end)
  32. return NULL;
  33. return (void __iomem *)(mips_io_port_base + port);
  34. }
  35. void ioport_unmap(void __iomem *addr)
  36. {
  37. }
  38. EXPORT_SYMBOL(ioport_map);
  39. EXPORT_SYMBOL(ioport_unmap);
  40. void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
  41. {
  42. unsigned long start, len, flags;
  43. if (dev == NULL)
  44. return NULL;
  45. start = pci_resource_start(dev, bar);
  46. len = pci_resource_len(dev, bar);
  47. if (!start || !len)
  48. return NULL;
  49. if (maxlen != 0 && len > maxlen)
  50. len = maxlen;
  51. flags = pci_resource_flags(dev, bar);
  52. if (flags & IORESOURCE_IO)
  53. return ioport_map(start, len);
  54. if (flags & IORESOURCE_MEM) {
  55. if (flags & IORESOURCE_CACHEABLE)
  56. return ioremap_cacheable_cow(start, len);
  57. return ioremap_nocache(start, len);
  58. }
  59. return NULL;
  60. }
  61. void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
  62. {
  63. iounmap(addr);
  64. }
  65. EXPORT_SYMBOL(pci_iomap);
  66. EXPORT_SYMBOL(pci_iounmap);