io_no.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _M68KNOMMU_IO_H
  3. #define _M68KNOMMU_IO_H
  4. /*
  5. * Convert a physical memory address into a IO memory address.
  6. * For us this is trivially a type cast.
  7. */
  8. #define iomem(a) ((void __iomem *) (a))
  9. /*
  10. * The non-MMU m68k and ColdFire IO and memory mapped hardware access
  11. * functions have always worked in CPU native endian. We need to define
  12. * that behavior here first before we include asm-generic/io.h.
  13. */
  14. #define __raw_readb(addr) \
  15. ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
  16. #define __raw_readw(addr) \
  17. ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
  18. #define __raw_readl(addr) \
  19. ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; })
  20. #define __raw_writeb(b, addr) (void)((*(volatile unsigned char *) (addr)) = (b))
  21. #define __raw_writew(b, addr) (void)((*(volatile unsigned short *) (addr)) = (b))
  22. #define __raw_writel(b, addr) (void)((*(volatile unsigned int *) (addr)) = (b))
  23. #if defined(CONFIG_COLDFIRE)
  24. /*
  25. * For ColdFire platforms we may need to do some extra checks for what
  26. * type of address range we are accessing. Include the ColdFire platform
  27. * definitions so we can figure out if need to do something special.
  28. */
  29. #include <asm/byteorder.h>
  30. #include <asm/coldfire.h>
  31. #include <asm/mcfsim.h>
  32. #endif /* CONFIG_COLDFIRE */
  33. #if defined(IOMEMBASE)
  34. /*
  35. * The ColdFire SoC internal peripherals are mapped into virtual address
  36. * space using the ACR registers of the cache control unit. This means we
  37. * are using a 1:1 physical:virtual mapping for them. We can quickly
  38. * determine if we are accessing an internal peripheral device given the
  39. * physical or vitrual address using the same range check. This check logic
  40. * applies just the same of there is no MMU but something like a PCI bus
  41. * is present.
  42. */
  43. static int __cf_internalio(unsigned long addr)
  44. {
  45. return (addr >= IOMEMBASE) && (addr <= IOMEMBASE + IOMEMSIZE - 1);
  46. }
  47. static int cf_internalio(const volatile void __iomem *addr)
  48. {
  49. return __cf_internalio((unsigned long) addr);
  50. }
  51. /*
  52. * We need to treat built-in peripherals and bus based address ranges
  53. * differently. Local built-in peripherals (and the ColdFire SoC parts
  54. * have quite a lot of them) are always native endian - which is big
  55. * endian on m68k/ColdFire. Bus based address ranges, like the PCI bus,
  56. * are accessed little endian - so we need to byte swap those.
  57. */
  58. #define readw readw
  59. static inline u16 readw(const volatile void __iomem *addr)
  60. {
  61. if (cf_internalio(addr))
  62. return __raw_readw(addr);
  63. return __le16_to_cpu(__raw_readw(addr));
  64. }
  65. #define readl readl
  66. static inline u32 readl(const volatile void __iomem *addr)
  67. {
  68. if (cf_internalio(addr))
  69. return __raw_readl(addr);
  70. return __le32_to_cpu(__raw_readl(addr));
  71. }
  72. #define writew writew
  73. static inline void writew(u16 value, volatile void __iomem *addr)
  74. {
  75. if (cf_internalio(addr))
  76. __raw_writew(value, addr);
  77. else
  78. __raw_writew(__cpu_to_le16(value), addr);
  79. }
  80. #define writel writel
  81. static inline void writel(u32 value, volatile void __iomem *addr)
  82. {
  83. if (cf_internalio(addr))
  84. __raw_writel(value, addr);
  85. else
  86. __raw_writel(__cpu_to_le32(value), addr);
  87. }
  88. #else
  89. #define readb __raw_readb
  90. #define readw __raw_readw
  91. #define readl __raw_readl
  92. #define writeb __raw_writeb
  93. #define writew __raw_writew
  94. #define writel __raw_writel
  95. #endif /* IOMEMBASE */
  96. #if defined(CONFIG_PCI)
  97. /*
  98. * Support for PCI bus access uses the asm-generic access functions.
  99. * We need to supply the base address and masks for the normal memory
  100. * and IO address space mappings.
  101. */
  102. #define PCI_MEM_PA 0xf0000000 /* Host physical address */
  103. #define PCI_MEM_BA 0xf0000000 /* Bus physical address */
  104. #define PCI_MEM_SIZE 0x08000000 /* 128 MB */
  105. #define PCI_MEM_MASK (PCI_MEM_SIZE - 1)
  106. #define PCI_IO_PA 0xf8000000 /* Host physical address */
  107. #define PCI_IO_BA 0x00000000 /* Bus physical address */
  108. #define PCI_IO_SIZE 0x00010000 /* 64k */
  109. #define PCI_IO_MASK (PCI_IO_SIZE - 1)
  110. #define HAVE_ARCH_PIO_SIZE
  111. #define PIO_OFFSET 0
  112. #define PIO_MASK 0xffff
  113. #define PIO_RESERVED 0x10000
  114. #define PCI_IOBASE ((void __iomem *) PCI_IO_PA)
  115. #define PCI_SPACE_LIMIT PCI_IO_MASK
  116. #endif /* CONFIG_PCI */
  117. #include <asm/kmap.h>
  118. #include <asm/virtconvert.h>
  119. #endif /* _M68KNOMMU_IO_H */