cache.h 4.0 KB

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