copy_page.S 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/linkage.h>
  17. #include <linux/const.h>
  18. #include <asm/assembler.h>
  19. #include <asm/page.h>
  20. #include <asm/cpufeature.h>
  21. #include <asm/alternative.h>
  22. /*
  23. * Copy a page from src to dest (both are page aligned)
  24. *
  25. * Parameters:
  26. * x0 - dest
  27. * x1 - src
  28. */
  29. ENTRY(copy_page)
  30. alternative_if ARM64_HAS_NO_HW_PREFETCH
  31. // Prefetch three cache lines ahead.
  32. prfm pldl1strm, [x1, #128]
  33. prfm pldl1strm, [x1, #256]
  34. prfm pldl1strm, [x1, #384]
  35. alternative_else_nop_endif
  36. ldp x2, x3, [x1]
  37. ldp x4, x5, [x1, #16]
  38. ldp x6, x7, [x1, #32]
  39. ldp x8, x9, [x1, #48]
  40. ldp x10, x11, [x1, #64]
  41. ldp x12, x13, [x1, #80]
  42. ldp x14, x15, [x1, #96]
  43. ldp x16, x17, [x1, #112]
  44. add x0, x0, #256
  45. add x1, x1, #128
  46. 1:
  47. tst x0, #(PAGE_SIZE - 1)
  48. alternative_if ARM64_HAS_NO_HW_PREFETCH
  49. prfm pldl1strm, [x1, #384]
  50. alternative_else_nop_endif
  51. stnp x2, x3, [x0, #-256]
  52. ldp x2, x3, [x1]
  53. stnp x4, x5, [x0, #16 - 256]
  54. ldp x4, x5, [x1, #16]
  55. stnp x6, x7, [x0, #32 - 256]
  56. ldp x6, x7, [x1, #32]
  57. stnp x8, x9, [x0, #48 - 256]
  58. ldp x8, x9, [x1, #48]
  59. stnp x10, x11, [x0, #64 - 256]
  60. ldp x10, x11, [x1, #64]
  61. stnp x12, x13, [x0, #80 - 256]
  62. ldp x12, x13, [x1, #80]
  63. stnp x14, x15, [x0, #96 - 256]
  64. ldp x14, x15, [x1, #96]
  65. stnp x16, x17, [x0, #112 - 256]
  66. ldp x16, x17, [x1, #112]
  67. add x0, x0, #128
  68. add x1, x1, #128
  69. b.ne 1b
  70. stnp x2, x3, [x0, #-256]
  71. stnp x4, x5, [x0, #16 - 256]
  72. stnp x6, x7, [x0, #32 - 256]
  73. stnp x8, x9, [x0, #48 - 256]
  74. stnp x10, x11, [x0, #64 - 256]
  75. stnp x12, x13, [x0, #80 - 256]
  76. stnp x14, x15, [x0, #96 - 256]
  77. stnp x16, x17, [x0, #112 - 256]
  78. ret
  79. ENDPROC(copy_page)