vac-ops.h 4.2 KB

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