您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

arm_io.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2016 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/arm_io.h>
  26. /** @file
  27. *
  28. * iPXE I/O API for ARM
  29. *
  30. */
  31. /** An ARM I/O qword */
  32. union arm32_io_qword {
  33. uint64_t qword;
  34. uint32_t dword[2];
  35. };
  36. /**
  37. * Read 64-bit qword from memory-mapped device
  38. *
  39. * @v io_addr I/O address
  40. * @ret data Value read
  41. *
  42. * This is not atomic for ARM32.
  43. */
  44. static uint64_t arm32_readq ( volatile uint64_t *io_addr ) {
  45. volatile union arm32_io_qword *ptr =
  46. container_of ( io_addr, union arm32_io_qword, qword );
  47. union arm32_io_qword tmp;
  48. tmp.dword[0] = readl ( &ptr->dword[0] );
  49. tmp.dword[1] = readl ( &ptr->dword[1] );
  50. return tmp.qword;
  51. }
  52. /**
  53. * Write 64-bit qword to memory-mapped device
  54. *
  55. * @v data Value to write
  56. * @v io_addr I/O address
  57. *
  58. * This is not atomic for ARM32.
  59. */
  60. static void arm32_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
  61. volatile union arm32_io_qword *ptr =
  62. container_of ( io_addr, union arm32_io_qword, qword );
  63. union arm32_io_qword tmp;
  64. tmp.qword = data;
  65. writel ( tmp.dword[0], &ptr->dword[0] );
  66. writel ( tmp.dword[1], &ptr->dword[1] );
  67. }
  68. PROVIDE_IOAPI_INLINE ( arm, phys_to_bus );
  69. PROVIDE_IOAPI_INLINE ( arm, bus_to_phys );
  70. PROVIDE_IOAPI_INLINE ( arm, readb );
  71. PROVIDE_IOAPI_INLINE ( arm, readw );
  72. PROVIDE_IOAPI_INLINE ( arm, readl );
  73. PROVIDE_IOAPI_INLINE ( arm, writeb );
  74. PROVIDE_IOAPI_INLINE ( arm, writew );
  75. PROVIDE_IOAPI_INLINE ( arm, writel );
  76. PROVIDE_IOAPI_INLINE ( arm, iodelay );
  77. PROVIDE_IOAPI_INLINE ( arm, mb );
  78. #ifdef __aarch64__
  79. PROVIDE_IOAPI_INLINE ( arm, readq );
  80. PROVIDE_IOAPI_INLINE ( arm, writeq );
  81. #else
  82. PROVIDE_IOAPI ( arm, readq, arm32_readq );
  83. PROVIDE_IOAPI ( arm, writeq, arm32_writeq );
  84. #endif