vac-ops.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef _SPARC_VAC_OPS_H
  2. #define _SPARC_VAC_OPS_H
  3. /* vac-ops.h: Inline assembly routines to do operations on the Sparc
  4. * VAC (virtual address cache) for the sun4c.
  5. *
  6. * Copyright (C) 1994, David S. Miller (davem@caip.rutgers.edu)
  7. */
  8. #include <asm/sysen.h>
  9. #include <asm/contregs.h>
  10. #include <asm/asi.h>
  11. /* The SUN4C models have a virtually addressed write-through
  12. * cache.
  13. *
  14. * The cache tags are directly accessible through an ASI and
  15. * each have the form:
  16. *
  17. * ------------------------------------------------------------
  18. * | MBZ | CONTEXT | WRITE | PRIV | VALID | MBZ | TagID | MBZ |
  19. * ------------------------------------------------------------
  20. * 31 25 24 22 21 20 19 18 16 15 2 1 0
  21. *
  22. * MBZ: These bits are either unused and/or reserved and should
  23. * be written as zeroes.
  24. *
  25. * CONTEXT: Records the context to which this cache line belongs.
  26. *
  27. * WRITE: A copy of the writable bit from the mmu pte access bits.
  28. *
  29. * PRIV: A copy of the privileged bit from the pte access bits.
  30. *
  31. * VALID: If set, this line is valid, else invalid.
  32. *
  33. * TagID: Fourteen bits of tag ID.
  34. *
  35. * Every virtual address is seen by the cache like this:
  36. *
  37. * ----------------------------------------
  38. * | RESV | TagID | LINE | BYTE-in-LINE |
  39. * ----------------------------------------
  40. * 31 30 29 16 15 4 3 0
  41. *
  42. * RESV: Unused/reserved.
  43. *
  44. * TagID: Used to match the Tag-ID in that vac tags.
  45. *
  46. * LINE: Which line within the cache
  47. *
  48. * BYTE-in-LINE: Which byte within the cache line.
  49. */
  50. /* Sun4c VAC Tags */
  51. #define S4CVACTAG_CID 0x01c00000
  52. #define S4CVACTAG_W 0x00200000
  53. #define S4CVACTAG_P 0x00100000
  54. #define S4CVACTAG_V 0x00080000
  55. #define S4CVACTAG_TID 0x0000fffc
  56. /* Sun4c VAC Virtual Address */
  57. /* These aren't used, why bother? (Anton) */
  58. #if 0
  59. #define S4CVACVA_TID 0x3fff0000
  60. #define S4CVACVA_LINE 0x0000fff0
  61. #define S4CVACVA_BIL 0x0000000f
  62. #endif
  63. /* The indexing of cache lines creates a problem. Because the line
  64. * field of a virtual address extends past the page offset within
  65. * the virtual address it is possible to have what are called
  66. * 'bad aliases' which will create inconsistencies. So we must make
  67. * sure that within a context that if a physical page is mapped
  68. * more than once, that 'extra' line bits are the same. If this is
  69. * not the case, and thus is a 'bad alias' we must turn off the
  70. * cacheable bit in the pte's of all such pages.
  71. */
  72. #define S4CVAC_BADBITS 0x0000f000
  73. /* The following is true if vaddr1 and vaddr2 would cause
  74. * a 'bad alias'.
  75. */
  76. #define S4CVAC_BADALIAS(vaddr1, vaddr2) \
  77. ((((unsigned long) (vaddr1)) ^ ((unsigned long) (vaddr2))) & \
  78. (S4CVAC_BADBITS))
  79. /* The following structure describes the characteristics of a sun4c
  80. * VAC as probed from the prom during boot time.
  81. */
  82. struct sun4c_vac_props {
  83. unsigned int num_bytes; /* Size of the cache */
  84. unsigned int do_hwflushes; /* Hardware flushing available? */
  85. unsigned int linesize; /* Size of each line in bytes */
  86. unsigned int log2lsize; /* log2(linesize) */
  87. unsigned int on; /* VAC is enabled */
  88. };
  89. extern struct sun4c_vac_props sun4c_vacinfo;
  90. /* sun4c_enable_vac() enables the sun4c virtual address cache. */
  91. static inline void sun4c_enable_vac(void)
  92. {
  93. __asm__ __volatile__("lduba [%0] %1, %%g1\n\t"
  94. "or %%g1, %2, %%g1\n\t"
  95. "stba %%g1, [%0] %1\n\t"
  96. : /* no outputs */
  97. : "r" ((unsigned int) AC_SENABLE),
  98. "i" (ASI_CONTROL), "i" (SENABLE_CACHE)
  99. : "g1", "memory");
  100. sun4c_vacinfo.on = 1;
  101. }
  102. /* sun4c_disable_vac() disables the virtual address cache. */
  103. static inline void sun4c_disable_vac(void)
  104. {
  105. __asm__ __volatile__("lduba [%0] %1, %%g1\n\t"
  106. "andn %%g1, %2, %%g1\n\t"
  107. "stba %%g1, [%0] %1\n\t"
  108. : /* no outputs */
  109. : "r" ((unsigned int) AC_SENABLE),
  110. "i" (ASI_CONTROL), "i" (SENABLE_CACHE)
  111. : "g1", "memory");
  112. sun4c_vacinfo.on = 0;
  113. }
  114. #endif /* !(_SPARC_VAC_OPS_H) */