You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <ipxe/io.h>
  25. #include <ipxe/x86_io.h>
  26. /** @file
  27. *
  28. * iPXE I/O API for x86
  29. *
  30. */
  31. /**
  32. * Read 64-bit qword from memory-mapped device
  33. *
  34. * @v io_addr I/O address
  35. * @ret data Value read
  36. *
  37. * This routine uses MMX instructions.
  38. */
  39. static __unused uint64_t i386_readq ( volatile uint64_t *io_addr ) {
  40. uint64_t data;
  41. __asm__ __volatile__ ( "pushl %%edx\n\t"
  42. "pushl %%eax\n\t"
  43. "movq (%1), %%mm0\n\t"
  44. "movq %%mm0, (%%esp)\n\t"
  45. "popl %%eax\n\t"
  46. "popl %%edx\n\t"
  47. "emms\n\t"
  48. : "=A" ( data ) : "r" ( io_addr ) );
  49. return data;
  50. }
  51. /**
  52. * Write 64-bit qword to memory-mapped device
  53. *
  54. * @v data Value to write
  55. * @v io_addr I/O address
  56. *
  57. * This routine uses MMX instructions.
  58. */
  59. static __unused void i386_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
  60. __asm__ __volatile__ ( "pushl %%edx\n\t"
  61. "pushl %%eax\n\t"
  62. "movq (%%esp), %%mm0\n\t"
  63. "movq %%mm0, (%1)\n\t"
  64. "popl %%eax\n\t"
  65. "popl %%edx\n\t"
  66. "emms\n\t"
  67. : : "A" ( data ), "r" ( io_addr ) );
  68. }
  69. PROVIDE_IOAPI_INLINE ( x86, phys_to_bus );
  70. PROVIDE_IOAPI_INLINE ( x86, bus_to_phys );
  71. PROVIDE_IOAPI_INLINE ( x86, readb );
  72. PROVIDE_IOAPI_INLINE ( x86, readw );
  73. PROVIDE_IOAPI_INLINE ( x86, readl );
  74. PROVIDE_IOAPI_INLINE ( x86, writeb );
  75. PROVIDE_IOAPI_INLINE ( x86, writew );
  76. PROVIDE_IOAPI_INLINE ( x86, writel );
  77. PROVIDE_IOAPI_INLINE ( x86, inb );
  78. PROVIDE_IOAPI_INLINE ( x86, inw );
  79. PROVIDE_IOAPI_INLINE ( x86, inl );
  80. PROVIDE_IOAPI_INLINE ( x86, outb );
  81. PROVIDE_IOAPI_INLINE ( x86, outw );
  82. PROVIDE_IOAPI_INLINE ( x86, outl );
  83. PROVIDE_IOAPI_INLINE ( x86, insb );
  84. PROVIDE_IOAPI_INLINE ( x86, insw );
  85. PROVIDE_IOAPI_INLINE ( x86, insl );
  86. PROVIDE_IOAPI_INLINE ( x86, outsb );
  87. PROVIDE_IOAPI_INLINE ( x86, outsw );
  88. PROVIDE_IOAPI_INLINE ( x86, outsl );
  89. PROVIDE_IOAPI_INLINE ( x86, iodelay );
  90. PROVIDE_IOAPI_INLINE ( x86, mb );
  91. #ifdef __x86_64__
  92. PROVIDE_IOAPI_INLINE ( x86, readq );
  93. PROVIDE_IOAPI_INLINE ( x86, writeq );
  94. #else
  95. PROVIDE_IOAPI ( x86, readq, i386_readq );
  96. PROVIDE_IOAPI ( x86, writeq, i386_writeq );
  97. #endif