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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <ipxe/io.h>
  20. #include <ipxe/x86_io.h>
  21. /** @file
  22. *
  23. * iPXE I/O API for x86
  24. *
  25. */
  26. /**
  27. * Read 64-bit qword from memory-mapped device
  28. *
  29. * @v io_addr I/O address
  30. * @ret data Value read
  31. *
  32. * This routine uses MMX instructions.
  33. */
  34. static uint64_t x86_readq ( volatile uint64_t *io_addr ) {
  35. uint64_t data;
  36. __asm__ __volatile__ ( "pushl %%edx\n\t"
  37. "pushl %%eax\n\t"
  38. "movq (%1), %%mm0\n\t"
  39. "movq %%mm0, (%%esp)\n\t"
  40. "popl %%eax\n\t"
  41. "popl %%edx\n\t"
  42. "emms\n\t"
  43. : "=A" ( data ) : "r" ( io_addr ) );
  44. return data;
  45. }
  46. /**
  47. * Write 64-bit qword to memory-mapped device
  48. *
  49. * @v data Value to write
  50. * @v io_addr I/O address
  51. *
  52. * This routine uses MMX instructions.
  53. */
  54. static void x86_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
  55. __asm__ __volatile__ ( "pushl %%edx\n\t"
  56. "pushl %%eax\n\t"
  57. "movq (%%esp), %%mm0\n\t"
  58. "movq %%mm0, (%1)\n\t"
  59. "popl %%eax\n\t"
  60. "popl %%edx\n\t"
  61. "emms\n\t"
  62. : : "A" ( data ), "r" ( io_addr ) );
  63. }
  64. PROVIDE_IOAPI_INLINE ( x86, phys_to_bus );
  65. PROVIDE_IOAPI_INLINE ( x86, bus_to_phys );
  66. PROVIDE_IOAPI_INLINE ( x86, ioremap );
  67. PROVIDE_IOAPI_INLINE ( x86, iounmap );
  68. PROVIDE_IOAPI_INLINE ( x86, io_to_bus );
  69. PROVIDE_IOAPI_INLINE ( x86, readb );
  70. PROVIDE_IOAPI_INLINE ( x86, readw );
  71. PROVIDE_IOAPI_INLINE ( x86, readl );
  72. PROVIDE_IOAPI ( x86, readq, x86_readq );
  73. PROVIDE_IOAPI_INLINE ( x86, writeb );
  74. PROVIDE_IOAPI_INLINE ( x86, writew );
  75. PROVIDE_IOAPI_INLINE ( x86, writel );
  76. PROVIDE_IOAPI ( x86, writeq, x86_writeq );
  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 );