cache.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * File : cache.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2010, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-05-17 swkyer first version
  13. */
  14. #include <rtthread.h>
  15. #include "mipscfg.h"
  16. #include "cache.h"
  17. extern void cache_init(rt_ubase_t cache_size, rt_ubase_t cache_line_size);
  18. void r4k_cache_init(void)
  19. {
  20. cache_init(dcache_size, cpu_dcache_line_size());
  21. }
  22. void r4k_cache_flush_all(void)
  23. {
  24. blast_dcache16();
  25. blast_icache16();
  26. }
  27. void r4k_icache_flush_all(void)
  28. {
  29. blast_icache16();
  30. }
  31. void r4k_icache_flush_range(rt_ubase_t addr, rt_ubase_t size)
  32. {
  33. rt_ubase_t end, a;
  34. if (size > icache_size)
  35. {
  36. blast_icache16();
  37. }
  38. else
  39. {
  40. rt_ubase_t ic_lsize = cpu_icache_line_size();
  41. a = addr & ~(ic_lsize - 1);
  42. end = ((addr + size) - 1) & ~(ic_lsize - 1);
  43. while (1)
  44. {
  45. flush_icache_line(a);
  46. if (a == end)
  47. break;
  48. a += ic_lsize;
  49. }
  50. }
  51. }
  52. void r4k_icache_lock_range(rt_ubase_t addr, rt_ubase_t size)
  53. {
  54. rt_ubase_t end, a;
  55. rt_ubase_t ic_lsize = cpu_icache_line_size();
  56. a = addr & ~(ic_lsize - 1);
  57. end = ((addr + size) - 1) & ~(ic_lsize - 1);
  58. while (1)
  59. {
  60. lock_icache_line(a);
  61. if (a == end)
  62. break;
  63. a += ic_lsize;
  64. }
  65. }
  66. void r4k_dcache_inv(rt_ubase_t addr, rt_ubase_t size)
  67. {
  68. rt_ubase_t end, a;
  69. rt_ubase_t dc_lsize = cpu_dcache_line_size();
  70. a = addr & ~(dc_lsize - 1);
  71. end = ((addr + size) - 1) & ~(dc_lsize - 1);
  72. while (1)
  73. {
  74. invalidate_dcache_line(a);
  75. if (a == end)
  76. break;
  77. a += dc_lsize;
  78. }
  79. }
  80. void r4k_dcache_wback_inv(rt_ubase_t addr, rt_ubase_t size)
  81. {
  82. rt_ubase_t end, a;
  83. if (size >= dcache_size)
  84. {
  85. blast_dcache16();
  86. }
  87. else
  88. {
  89. rt_ubase_t dc_lsize = cpu_dcache_line_size();
  90. a = addr & ~(dc_lsize - 1);
  91. end = ((addr + size) - 1) & ~(dc_lsize - 1);
  92. while (1)
  93. {
  94. flush_dcache_line(a);
  95. if (a == end)
  96. break;
  97. a += dc_lsize;
  98. }
  99. }
  100. }