misc.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * This file contains miscellaneous low-level functions.
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
  6. * and Paul Mackerras.
  7. *
  8. * A couple of functions stolen from arch/ppc/kernel/misc.S for UML
  9. * by Chris Emerson.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. *
  16. */
  17. #include <linux/config.h>
  18. #include <asm/processor.h>
  19. #include "ppc_asm.h"
  20. #if defined(CONFIG_4xx) || defined(CONFIG_8xx)
  21. #define CACHE_LINE_SIZE 16
  22. #define LG_CACHE_LINE_SIZE 4
  23. #define MAX_COPY_PREFETCH 1
  24. #else
  25. #define CACHE_LINE_SIZE 32
  26. #define LG_CACHE_LINE_SIZE 5
  27. #define MAX_COPY_PREFETCH 4
  28. #endif /* CONFIG_4xx || CONFIG_8xx */
  29. .text
  30. /*
  31. * Clear a page using the dcbz instruction, which doesn't cause any
  32. * memory traffic (except to write out any cache lines which get
  33. * displaced). This only works on cacheable memory.
  34. */
  35. _GLOBAL(clear_page)
  36. li r0,4096/CACHE_LINE_SIZE
  37. mtctr r0
  38. #ifdef CONFIG_8xx
  39. li r4, 0
  40. 1: stw r4, 0(r3)
  41. stw r4, 4(r3)
  42. stw r4, 8(r3)
  43. stw r4, 12(r3)
  44. #else
  45. 1: dcbz 0,r3
  46. #endif
  47. addi r3,r3,CACHE_LINE_SIZE
  48. bdnz 1b
  49. blr
  50. /*
  51. * Copy a whole page. We use the dcbz instruction on the destination
  52. * to reduce memory traffic (it eliminates the unnecessary reads of
  53. * the destination into cache). This requires that the destination
  54. * is cacheable.
  55. */
  56. #define COPY_16_BYTES \
  57. lwz r6,4(r4); \
  58. lwz r7,8(r4); \
  59. lwz r8,12(r4); \
  60. lwzu r9,16(r4); \
  61. stw r6,4(r3); \
  62. stw r7,8(r3); \
  63. stw r8,12(r3); \
  64. stwu r9,16(r3)
  65. _GLOBAL(copy_page)
  66. addi r3,r3,-4
  67. addi r4,r4,-4
  68. li r5,4
  69. #ifndef CONFIG_8xx
  70. #if MAX_COPY_PREFETCH > 1
  71. li r0,MAX_COPY_PREFETCH
  72. li r11,4
  73. mtctr r0
  74. 11: dcbt r11,r4
  75. addi r11,r11,CACHE_LINE_SIZE
  76. bdnz 11b
  77. #else /* MAX_COPY_PREFETCH == 1 */
  78. dcbt r5,r4
  79. li r11,CACHE_LINE_SIZE+4
  80. #endif /* MAX_COPY_PREFETCH */
  81. #endif /* CONFIG_8xx */
  82. li r0,4096/CACHE_LINE_SIZE
  83. mtctr r0
  84. 1:
  85. #ifndef CONFIG_8xx
  86. dcbt r11,r4
  87. dcbz r5,r3
  88. #endif
  89. COPY_16_BYTES
  90. #if CACHE_LINE_SIZE >= 32
  91. COPY_16_BYTES
  92. #if CACHE_LINE_SIZE >= 64
  93. COPY_16_BYTES
  94. COPY_16_BYTES
  95. #if CACHE_LINE_SIZE >= 128
  96. COPY_16_BYTES
  97. COPY_16_BYTES
  98. COPY_16_BYTES
  99. COPY_16_BYTES
  100. #endif
  101. #endif
  102. #endif
  103. bdnz 1b
  104. blr