cache.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* cache.h: Cache specific code for the Sparc. These include flushing
  2. * and direct tag/data line access.
  3. *
  4. * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
  5. */
  6. #ifndef _SPARC_CACHE_H
  7. #define _SPARC_CACHE_H
  8. #define L1_CACHE_SHIFT 5
  9. #define L1_CACHE_BYTES 32
  10. #define L1_CACHE_ALIGN(x) ((((x)+(L1_CACHE_BYTES-1))&~(L1_CACHE_BYTES-1)))
  11. #ifdef CONFIG_SPARC32
  12. #define SMP_CACHE_BYTES_SHIFT 5
  13. #else
  14. #define SMP_CACHE_BYTES_SHIFT 6
  15. #endif
  16. #define SMP_CACHE_BYTES (1 << SMP_CACHE_BYTES_SHIFT)
  17. #define __read_mostly __attribute__((__section__(".data.read_mostly")))
  18. #ifdef CONFIG_SPARC32
  19. #include <asm/asi.h>
  20. /* Direct access to the instruction cache is provided through and
  21. * alternate address space. The IDC bit must be off in the ICCR on
  22. * HyperSparcs for these accesses to work. The code below does not do
  23. * any checking, the caller must do so. These routines are for
  24. * diagnostics only, but could end up being useful. Use with care.
  25. * Also, you are asking for trouble if you execute these in one of the
  26. * three instructions following a %asr/%psr access or modification.
  27. */
  28. /* First, cache-tag access. */
  29. static inline unsigned int get_icache_tag(int setnum, int tagnum)
  30. {
  31. unsigned int vaddr, retval;
  32. vaddr = ((setnum&1) << 12) | ((tagnum&0x7f) << 5);
  33. __asm__ __volatile__("lda [%1] %2, %0\n\t" :
  34. "=r" (retval) :
  35. "r" (vaddr), "i" (ASI_M_TXTC_TAG));
  36. return retval;
  37. }
  38. static inline void put_icache_tag(int setnum, int tagnum, unsigned int entry)
  39. {
  40. unsigned int vaddr;
  41. vaddr = ((setnum&1) << 12) | ((tagnum&0x7f) << 5);
  42. __asm__ __volatile__("sta %0, [%1] %2\n\t" : :
  43. "r" (entry), "r" (vaddr), "i" (ASI_M_TXTC_TAG) :
  44. "memory");
  45. }
  46. /* Second cache-data access. The data is returned two-32bit quantities
  47. * at a time.
  48. */
  49. static inline void get_icache_data(int setnum, int tagnum, int subblock,
  50. unsigned int *data)
  51. {
  52. unsigned int value1, value2, vaddr;
  53. vaddr = ((setnum&0x1) << 12) | ((tagnum&0x7f) << 5) |
  54. ((subblock&0x3) << 3);
  55. __asm__ __volatile__("ldda [%2] %3, %%g2\n\t"
  56. "or %%g0, %%g2, %0\n\t"
  57. "or %%g0, %%g3, %1\n\t" :
  58. "=r" (value1), "=r" (value2) :
  59. "r" (vaddr), "i" (ASI_M_TXTC_DATA) :
  60. "g2", "g3");
  61. data[0] = value1; data[1] = value2;
  62. }
  63. static inline void put_icache_data(int setnum, int tagnum, int subblock,
  64. unsigned int *data)
  65. {
  66. unsigned int value1, value2, vaddr;
  67. vaddr = ((setnum&0x1) << 12) | ((tagnum&0x7f) << 5) |
  68. ((subblock&0x3) << 3);
  69. value1 = data[0]; value2 = data[1];
  70. __asm__ __volatile__("or %%g0, %0, %%g2\n\t"
  71. "or %%g0, %1, %%g3\n\t"
  72. "stda %%g2, [%2] %3\n\t" : :
  73. "r" (value1), "r" (value2),
  74. "r" (vaddr), "i" (ASI_M_TXTC_DATA) :
  75. "g2", "g3", "memory" /* no joke */);
  76. }
  77. /* Different types of flushes with the ICACHE. Some of the flushes
  78. * affect both the ICACHE and the external cache. Others only clear
  79. * the ICACHE entries on the cpu itself. V8's (most) allow
  80. * granularity of flushes on the packet (element in line), whole line,
  81. * and entire cache (ie. all lines) level. The ICACHE only flushes are
  82. * ROSS HyperSparc specific and are in ross.h
  83. */
  84. /* Flushes which clear out both the on-chip and external caches */
  85. static inline void flush_ei_page(unsigned int addr)
  86. {
  87. __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
  88. "r" (addr), "i" (ASI_M_FLUSH_PAGE) :
  89. "memory");
  90. }
  91. static inline void flush_ei_seg(unsigned int addr)
  92. {
  93. __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
  94. "r" (addr), "i" (ASI_M_FLUSH_SEG) :
  95. "memory");
  96. }
  97. static inline void flush_ei_region(unsigned int addr)
  98. {
  99. __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
  100. "r" (addr), "i" (ASI_M_FLUSH_REGION) :
  101. "memory");
  102. }
  103. static inline void flush_ei_ctx(unsigned int addr)
  104. {
  105. __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
  106. "r" (addr), "i" (ASI_M_FLUSH_CTX) :
  107. "memory");
  108. }
  109. static inline void flush_ei_user(unsigned int addr)
  110. {
  111. __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
  112. "r" (addr), "i" (ASI_M_FLUSH_USER) :
  113. "memory");
  114. }
  115. #endif /* CONFIG_SPARC32 */
  116. #endif /* !(_SPARC_CACHE_H) */