cache.h 3.9 KB

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