misc.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #elif !defined(CONFIG_PPC64BRIDGE)
  25. #define CACHE_LINE_SIZE 32
  26. #define LG_CACHE_LINE_SIZE 5
  27. #define MAX_COPY_PREFETCH 4
  28. #else
  29. #define CACHE_LINE_SIZE 128
  30. #define LG_CACHE_LINE_SIZE 7
  31. #define MAX_COPY_PREFETCH 1
  32. #endif /* CONFIG_4xx || CONFIG_8xx */
  33. .text
  34. /*
  35. * Clear a page using the dcbz instruction, which doesn't cause any
  36. * memory traffic (except to write out any cache lines which get
  37. * displaced). This only works on cacheable memory.
  38. */
  39. _GLOBAL(clear_page)
  40. li r0,4096/CACHE_LINE_SIZE
  41. mtctr r0
  42. #ifdef CONFIG_8xx
  43. li r4, 0
  44. 1: stw r4, 0(r3)
  45. stw r4, 4(r3)
  46. stw r4, 8(r3)
  47. stw r4, 12(r3)
  48. #else
  49. 1: dcbz 0,r3
  50. #endif
  51. addi r3,r3,CACHE_LINE_SIZE
  52. bdnz 1b
  53. blr
  54. /*
  55. * Copy a whole page. We use the dcbz instruction on the destination
  56. * to reduce memory traffic (it eliminates the unnecessary reads of
  57. * the destination into cache). This requires that the destination
  58. * is cacheable.
  59. */
  60. #define COPY_16_BYTES \
  61. lwz r6,4(r4); \
  62. lwz r7,8(r4); \
  63. lwz r8,12(r4); \
  64. lwzu r9,16(r4); \
  65. stw r6,4(r3); \
  66. stw r7,8(r3); \
  67. stw r8,12(r3); \
  68. stwu r9,16(r3)
  69. _GLOBAL(copy_page)
  70. addi r3,r3,-4
  71. addi r4,r4,-4
  72. li r5,4
  73. #ifndef CONFIG_8xx
  74. #if MAX_COPY_PREFETCH > 1
  75. li r0,MAX_COPY_PREFETCH
  76. li r11,4
  77. mtctr r0
  78. 11: dcbt r11,r4
  79. addi r11,r11,CACHE_LINE_SIZE
  80. bdnz 11b
  81. #else /* MAX_COPY_PREFETCH == 1 */
  82. dcbt r5,r4
  83. li r11,CACHE_LINE_SIZE+4
  84. #endif /* MAX_COPY_PREFETCH */
  85. #endif /* CONFIG_8xx */
  86. li r0,4096/CACHE_LINE_SIZE
  87. mtctr r0
  88. 1:
  89. #ifndef CONFIG_8xx
  90. dcbt r11,r4
  91. dcbz r5,r3
  92. #endif
  93. COPY_16_BYTES
  94. #if CACHE_LINE_SIZE >= 32
  95. COPY_16_BYTES
  96. #if CACHE_LINE_SIZE >= 64
  97. COPY_16_BYTES
  98. COPY_16_BYTES
  99. #if CACHE_LINE_SIZE >= 128
  100. COPY_16_BYTES
  101. COPY_16_BYTES
  102. COPY_16_BYTES
  103. COPY_16_BYTES
  104. #endif
  105. #endif
  106. #endif
  107. bdnz 1b
  108. blr