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.

x86_io.c 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <ipxe/io.h>
  21. #include <ipxe/x86_io.h>
  22. /** @file
  23. *
  24. * iPXE I/O API for x86
  25. *
  26. */
  27. /**
  28. * Read 64-bit qword from memory-mapped device
  29. *
  30. * @v io_addr I/O address
  31. * @ret data Value read
  32. *
  33. * This routine uses MMX instructions.
  34. */
  35. static __unused uint64_t i386_readq ( volatile uint64_t *io_addr ) {
  36. uint64_t data;
  37. __asm__ __volatile__ ( "pushl %%edx\n\t"
  38. "pushl %%eax\n\t"
  39. "movq (%1), %%mm0\n\t"
  40. "movq %%mm0, (%%esp)\n\t"
  41. "popl %%eax\n\t"
  42. "popl %%edx\n\t"
  43. "emms\n\t"
  44. : "=A" ( data ) : "r" ( io_addr ) );
  45. return data;
  46. }
  47. /**
  48. * Write 64-bit qword to memory-mapped device
  49. *
  50. * @v data Value to write
  51. * @v io_addr I/O address
  52. *
  53. * This routine uses MMX instructions.
  54. */
  55. static __unused void i386_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
  56. __asm__ __volatile__ ( "pushl %%edx\n\t"
  57. "pushl %%eax\n\t"
  58. "movq (%%esp), %%mm0\n\t"
  59. "movq %%mm0, (%1)\n\t"
  60. "popl %%eax\n\t"
  61. "popl %%edx\n\t"
  62. "emms\n\t"
  63. : : "A" ( data ), "r" ( io_addr ) );
  64. }
  65. PROVIDE_IOAPI_INLINE ( x86, phys_to_bus );
  66. PROVIDE_IOAPI_INLINE ( x86, bus_to_phys );
  67. PROVIDE_IOAPI_INLINE ( x86, ioremap );
  68. PROVIDE_IOAPI_INLINE ( x86, iounmap );
  69. PROVIDE_IOAPI_INLINE ( x86, io_to_bus );
  70. PROVIDE_IOAPI_INLINE ( x86, readb );
  71. PROVIDE_IOAPI_INLINE ( x86, readw );
  72. PROVIDE_IOAPI_INLINE ( x86, readl );
  73. PROVIDE_IOAPI_INLINE ( x86, writeb );
  74. PROVIDE_IOAPI_INLINE ( x86, writew );
  75. PROVIDE_IOAPI_INLINE ( x86, writel );
  76. PROVIDE_IOAPI_INLINE ( x86, inb );
  77. PROVIDE_IOAPI_INLINE ( x86, inw );
  78. PROVIDE_IOAPI_INLINE ( x86, inl );
  79. PROVIDE_IOAPI_INLINE ( x86, outb );
  80. PROVIDE_IOAPI_INLINE ( x86, outw );
  81. PROVIDE_IOAPI_INLINE ( x86, outl );
  82. PROVIDE_IOAPI_INLINE ( x86, insb );
  83. PROVIDE_IOAPI_INLINE ( x86, insw );
  84. PROVIDE_IOAPI_INLINE ( x86, insl );
  85. PROVIDE_IOAPI_INLINE ( x86, outsb );
  86. PROVIDE_IOAPI_INLINE ( x86, outsw );
  87. PROVIDE_IOAPI_INLINE ( x86, outsl );
  88. PROVIDE_IOAPI_INLINE ( x86, iodelay );
  89. PROVIDE_IOAPI_INLINE ( x86, mb );
  90. #ifdef __x86_64__
  91. PROVIDE_IOAPI_INLINE ( x86, readq );
  92. PROVIDE_IOAPI_INLINE ( x86, writeq );
  93. #else
  94. PROVIDE_IOAPI ( x86, readq, i386_readq );
  95. PROVIDE_IOAPI ( x86, writeq, i386_writeq );
  96. #endif