vac-ops.h 4.2 KB

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