cache-v7-min.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * This is a part of mm/cache-v7.S with extracted entry flushing D-cache. We
  3. * need it for Broadcom devices with broken bootloader leaving cache enabled.
  4. *
  5. * Copyright (C) 2001 Deep Blue Solutions Ltd.
  6. * Copyright (C) 2005 ARM Ltd.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/linkage.h>
  13. #include <linux/init.h>
  14. __INIT
  15. /*
  16. * v7_flush_dcache_all()
  17. *
  18. * Flush the whole D-cache.
  19. *
  20. * Corrupted registers: r0-r7, r9-r11 (r6 only in Thumb mode)
  21. *
  22. * - mm - mm_struct describing address space
  23. */
  24. ENTRY(v7_flush_dcache_all)
  25. dmb @ ensure ordering with previous memory accesses
  26. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  27. mov r3, r0, lsr #23 @ move LoC into position
  28. ands r3, r3, #7 << 1 @ extract LoC*2 from clidr
  29. beq finished @ if loc is 0, then no need to clean
  30. start_flush_levels:
  31. mov r10, #0 @ start clean at cache level 0
  32. flush_levels:
  33. add r2, r10, r10, lsr #1 @ work out 3x current cache level
  34. mov r1, r0, lsr r2 @ extract cache type bits from clidr
  35. and r1, r1, #7 @ mask of the bits for current cache only
  36. cmp r1, #2 @ see what cache we have at this level
  37. blt skip @ skip if no cache, or just i-cache
  38. #ifdef CONFIG_PREEMPT
  39. save_and_disable_irqs_notrace r9 @ make cssr&csidr read atomic
  40. #endif
  41. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  42. isb @ isb to sych the new cssr&csidr
  43. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  44. #ifdef CONFIG_PREEMPT
  45. restore_irqs_notrace r9
  46. #endif
  47. and r2, r1, #7 @ extract the length of the cache lines
  48. add r2, r2, #4 @ add 4 (line length offset)
  49. movw r4, #0x3ff
  50. ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  51. clz r5, r4 @ find bit position of way size increment
  52. movw r7, #0x7fff
  53. ands r7, r7, r1, lsr #13 @ extract max number of the index size
  54. loop1:
  55. mov r9, r7 @ create working copy of max index
  56. loop2:
  57. ARM( orr r11, r10, r4, lsl r5 ) @ factor way and cache number into r11
  58. THUMB( lsl r6, r4, r5 )
  59. THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
  60. ARM( orr r11, r11, r9, lsl r2 ) @ factor index number into r11
  61. THUMB( lsl r6, r9, r2 )
  62. THUMB( orr r11, r11, r6 ) @ factor index number into r11
  63. mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  64. subs r9, r9, #1 @ decrement the index
  65. bge loop2
  66. subs r4, r4, #1 @ decrement the way
  67. bge loop1
  68. skip:
  69. add r10, r10, #2 @ increment cache number
  70. cmp r3, r10
  71. bgt flush_levels
  72. finished:
  73. mov r10, #0 @ swith back to cache level 0
  74. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  75. dsb st
  76. isb
  77. ret lr
  78. ENDPROC(v7_flush_dcache_all)