cache.h 4.1 KB

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