io.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * include/asm-sh/io_bigsur.c
  3. *
  4. * By Dustin McIntire (dustin@sensoria.com) (c)2001
  5. * Derived from io_hd64465.h, which bore the message:
  6. * By Greg Banks <gbanks@pocketpenguins.com>
  7. * (c) 2000 PocketPenguins Inc.
  8. * and from io_hd64461.h, which bore the message:
  9. * Copyright 2000 Stuart Menefy (stuart.menefy@st.com)
  10. *
  11. * May be copied or modified under the terms of the GNU General Public
  12. * License. See linux/COPYING for more information.
  13. *
  14. * IO functions for a Hitachi Big Sur Evaluation Board.
  15. */
  16. #include <linux/config.h>
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <asm/machvec.h>
  20. #include <asm/io.h>
  21. #include <asm/bigsur/bigsur.h>
  22. /* Low iomap maps port 0-1K to addresses in 8byte chunks */
  23. #define BIGSUR_IOMAP_LO_THRESH 0x400
  24. #define BIGSUR_IOMAP_LO_SHIFT 3
  25. #define BIGSUR_IOMAP_LO_MASK ((1<<BIGSUR_IOMAP_LO_SHIFT)-1)
  26. #define BIGSUR_IOMAP_LO_NMAP (BIGSUR_IOMAP_LO_THRESH>>BIGSUR_IOMAP_LO_SHIFT)
  27. static u32 bigsur_iomap_lo[BIGSUR_IOMAP_LO_NMAP];
  28. static u8 bigsur_iomap_lo_shift[BIGSUR_IOMAP_LO_NMAP];
  29. /* High iomap maps port 1K-64K to addresses in 1K chunks */
  30. #define BIGSUR_IOMAP_HI_THRESH 0x10000
  31. #define BIGSUR_IOMAP_HI_SHIFT 10
  32. #define BIGSUR_IOMAP_HI_MASK ((1<<BIGSUR_IOMAP_HI_SHIFT)-1)
  33. #define BIGSUR_IOMAP_HI_NMAP (BIGSUR_IOMAP_HI_THRESH>>BIGSUR_IOMAP_HI_SHIFT)
  34. static u32 bigsur_iomap_hi[BIGSUR_IOMAP_HI_NMAP];
  35. static u8 bigsur_iomap_hi_shift[BIGSUR_IOMAP_HI_NMAP];
  36. void bigsur_port_map(u32 baseport, u32 nports, u32 addr, u8 shift)
  37. {
  38. u32 port, endport = baseport + nports;
  39. pr_debug("bigsur_port_map(base=0x%0x, n=0x%0x, addr=0x%08x)\n",
  40. baseport, nports, addr);
  41. for (port = baseport ;
  42. port < endport && port < BIGSUR_IOMAP_LO_THRESH ;
  43. port += (1<<BIGSUR_IOMAP_LO_SHIFT)) {
  44. pr_debug(" maplo[0x%x] = 0x%08x\n", port, addr);
  45. bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = addr;
  46. bigsur_iomap_lo_shift[port>>BIGSUR_IOMAP_LO_SHIFT] = shift;
  47. addr += (1<<(BIGSUR_IOMAP_LO_SHIFT));
  48. }
  49. for (port = max_t(u32, baseport, BIGSUR_IOMAP_LO_THRESH);
  50. port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
  51. port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
  52. pr_debug(" maphi[0x%x] = 0x%08x\n", port, addr);
  53. bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = addr;
  54. bigsur_iomap_hi_shift[port>>BIGSUR_IOMAP_HI_SHIFT] = shift;
  55. addr += (1<<(BIGSUR_IOMAP_HI_SHIFT));
  56. }
  57. }
  58. EXPORT_SYMBOL(bigsur_port_map);
  59. void bigsur_port_unmap(u32 baseport, u32 nports)
  60. {
  61. u32 port, endport = baseport + nports;
  62. pr_debug("bigsur_port_unmap(base=0x%0x, n=0x%0x)\n", baseport, nports);
  63. for (port = baseport ;
  64. port < endport && port < BIGSUR_IOMAP_LO_THRESH ;
  65. port += (1<<BIGSUR_IOMAP_LO_SHIFT)) {
  66. bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = 0;
  67. }
  68. for (port = max_t(u32, baseport, BIGSUR_IOMAP_LO_THRESH);
  69. port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
  70. port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
  71. bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = 0;
  72. }
  73. }
  74. EXPORT_SYMBOL(bigsur_port_unmap);
  75. unsigned long bigsur_isa_port2addr(unsigned long port)
  76. {
  77. unsigned long addr = 0;
  78. unsigned char shift;
  79. /* Physical address not in P0, do nothing */
  80. if (PXSEG(port)) {
  81. addr = port;
  82. /* physical address in P0, map to P2 */
  83. } else if (port >= 0x30000) {
  84. addr = P2SEGADDR(port);
  85. /* Big Sur I/O + HD64465 registers 0x10000-0x30000 */
  86. } else if (port >= BIGSUR_IOMAP_HI_THRESH) {
  87. addr = BIGSUR_INTERNAL_BASE + (port - BIGSUR_IOMAP_HI_THRESH);
  88. /* Handle remapping of high IO/PCI IO ports */
  89. } else if (port >= BIGSUR_IOMAP_LO_THRESH) {
  90. addr = bigsur_iomap_hi[port >> BIGSUR_IOMAP_HI_SHIFT];
  91. shift = bigsur_iomap_hi_shift[port >> BIGSUR_IOMAP_HI_SHIFT];
  92. if (addr != 0)
  93. addr += (port & BIGSUR_IOMAP_HI_MASK) << shift;
  94. } else {
  95. /* Handle remapping of low IO ports */
  96. addr = bigsur_iomap_lo[port >> BIGSUR_IOMAP_LO_SHIFT];
  97. shift = bigsur_iomap_lo_shift[port >> BIGSUR_IOMAP_LO_SHIFT];
  98. if (addr != 0)
  99. addr += (port & BIGSUR_IOMAP_LO_MASK) << shift;
  100. }
  101. pr_debug("%s(0x%08lx) = 0x%08lx\n", __FUNCTION__, port, addr);
  102. return addr;
  103. }