plprcr_write.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * (C) Copyright 2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <mpc8xx.h>
  24. #include <ppc_asm.tmpl>
  25. #include <asm/cache.h>
  26. #define CACHE_CMD_ENABLE 0x02000000
  27. #define CACHE_CMD_DISABLE 0x04000000
  28. #define CACHE_CMD_LOAD_LOCK 0x06000000
  29. #define CACHE_CMD_UNLOCK_LINE 0x08000000
  30. #define CACHE_CMD_UNLOCK_ALL 0x0A000000
  31. #define CACHE_CMD_INVALIDATE 0x0C000000
  32. #define SPEED_PLPRCR_WAIT_5CYC 150
  33. #define _CACHE_ALIGN_SIZE 16
  34. .text
  35. .align 2
  36. .globl plprcr_write_866
  37. /*
  38. * void plprcr_write_866 (long plprcr)
  39. * Write PLPRCR, including workaround for device errata SIU4 and SIU9.
  40. */
  41. plprcr_write_866:
  42. mfspr r10, LR /* save the Link Register value */
  43. /* turn instruction cache on (no MMU required for instructions)
  44. */
  45. lis r4, CACHE_CMD_ENABLE@h
  46. ori r4, r4, CACHE_CMD_ENABLE@l
  47. mtspr IC_CST, r4
  48. isync
  49. /* clear IC_CST error bits
  50. */
  51. mfspr r4, IC_CST
  52. bl plprcr_here
  53. plprcr_here:
  54. mflr r5
  55. /* calculate relocation offset
  56. */
  57. lis r4, plprcr_here@h
  58. ori r4, r4, plprcr_here@l
  59. sub r5, r5, r4
  60. /* calculate first address of this function
  61. */
  62. lis r6, plprcr_write_866@h
  63. ori r6, r6, plprcr_write_866@l
  64. add r6, r6, r5
  65. /* calculate end address of this function
  66. */
  67. lis r7, plprcr_end@h
  68. ori r7, r7, plprcr_end@l
  69. add r7, r7, r5
  70. /* load and lock code addresses
  71. */
  72. mr r5, r6
  73. plprcr_loop:
  74. mtspr IC_ADR, r5
  75. addi r5, r5, _CACHE_ALIGN_SIZE /* increment by one line */
  76. lis r4, CACHE_CMD_LOAD_LOCK@h
  77. ori r4, r4, CACHE_CMD_LOAD_LOCK@l
  78. mtspr IC_CST, r4
  79. isync
  80. cmpw r5, r7
  81. blt plprcr_loop
  82. /* IC_CST error bits not evaluated
  83. */
  84. /* switch PLPRCR
  85. */
  86. mfspr r4, IMMR /* read IMMR */
  87. rlwinm r4, r4, 0, 0, 15 /* only high 16 bits count */
  88. /* write sequence according to MPC866 Errata
  89. */
  90. stw r3, PLPRCR(r4)
  91. isync
  92. lis r3, SPEED_PLPRCR_WAIT_5CYC@h
  93. ori r3, r3, SPEED_PLPRCR_WAIT_5CYC@l
  94. plprcr_wait:
  95. cmpwi r3, 0
  96. beq plprcr_wait_end
  97. nop
  98. subi r3, r3, 1
  99. b plprcr_wait
  100. plprcr_wait_end:
  101. /* unlock instruction cache but leave it enabled
  102. */
  103. lis r4, CACHE_CMD_UNLOCK_ALL@h
  104. ori r4, r4, CACHE_CMD_UNLOCK_ALL@l
  105. mtspr IC_CST, r4
  106. isync
  107. mtspr LR, r10 /* restore original Link Register value */
  108. blr
  109. plprcr_end: