iomv.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2000-2003 Silicon Graphics, Inc. All rights reserved.
  7. */
  8. #include <linux/module.h>
  9. #include <asm/io.h>
  10. #include <asm/delay.h>
  11. #include <asm/vga.h>
  12. #include <asm/sn/nodepda.h>
  13. #include <asm/sn/simulator.h>
  14. #include <asm/sn/pda.h>
  15. #include <asm/sn/sn_cpuid.h>
  16. #include <asm/sn/shub_mmr.h>
  17. #define IS_LEGACY_VGA_IOPORT(p) \
  18. (((p) >= 0x3b0 && (p) <= 0x3bb) || ((p) >= 0x3c0 && (p) <= 0x3df))
  19. /**
  20. * sn_io_addr - convert an in/out port to an i/o address
  21. * @port: port to convert
  22. *
  23. * Legacy in/out instructions are converted to ld/st instructions
  24. * on IA64. This routine will convert a port number into a valid
  25. * SN i/o address. Used by sn_in*() and sn_out*().
  26. */
  27. void *sn_io_addr(unsigned long port)
  28. {
  29. if (!IS_RUNNING_ON_SIMULATOR()) {
  30. if (IS_LEGACY_VGA_IOPORT(port))
  31. port += vga_console_iobase;
  32. /* On sn2, legacy I/O ports don't point at anything */
  33. if (port < (64 * 1024))
  34. return NULL;
  35. return ((void *)(port | __IA64_UNCACHED_OFFSET));
  36. } else {
  37. /* but the simulator uses them... */
  38. unsigned long addr;
  39. /*
  40. * word align port, but need more than 10 bits
  41. * for accessing registers in bedrock local block
  42. * (so we don't do port&0xfff)
  43. */
  44. addr = (is_shub2() ? 0xc00000028c000000UL : 0xc0000087cc000000UL) | ((port >> 2) << 12);
  45. if ((port >= 0x1f0 && port <= 0x1f7) || port == 0x3f6 || port == 0x3f7)
  46. addr |= port;
  47. return (void *)addr;
  48. }
  49. }
  50. EXPORT_SYMBOL(sn_io_addr);
  51. /**
  52. * __sn_mmiowb - I/O space memory barrier
  53. *
  54. * See include/asm-ia64/io.h and Documentation/DocBook/deviceiobook.tmpl
  55. * for details.
  56. *
  57. * On SN2, we wait for the PIO_WRITE_STATUS SHub register to clear.
  58. * See PV 871084 for details about the WAR about zero value.
  59. *
  60. */
  61. void __sn_mmiowb(void)
  62. {
  63. volatile unsigned long *adr = pda->pio_write_status_addr;
  64. unsigned long val = pda->pio_write_status_val;
  65. while ((*adr & SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK) != val)
  66. cpu_relax();
  67. }
  68. EXPORT_SYMBOL(__sn_mmiowb);