spu_utils.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * utils.h: Utilities for SPU-side of the context switch operation.
  3. *
  4. * (C) Copyright IBM 2005
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #ifndef _SPU_CONTEXT_UTILS_H_
  21. #define _SPU_CONTEXT_UTILS_H_
  22. /*
  23. * 64-bit safe EA.
  24. */
  25. typedef union {
  26. unsigned long long ull;
  27. unsigned int ui[2];
  28. } addr64;
  29. /*
  30. * 128-bit register template.
  31. */
  32. typedef union {
  33. unsigned int slot[4];
  34. vector unsigned int v;
  35. } spu_reg128v;
  36. /*
  37. * DMA list structure.
  38. */
  39. struct dma_list_elem {
  40. unsigned int size;
  41. unsigned int ea_low;
  42. };
  43. /*
  44. * Declare storage for 8-byte aligned DMA list.
  45. */
  46. struct dma_list_elem dma_list[15] __attribute__ ((aligned(8)));
  47. /*
  48. * External definition for storage
  49. * declared in crt0.
  50. */
  51. extern spu_reg128v regs_spill[NR_SPU_SPILL_REGS];
  52. /*
  53. * Compute LSCSA byte offset for a given field.
  54. */
  55. static struct spu_lscsa *dummy = (struct spu_lscsa *)0;
  56. #define LSCSA_BYTE_OFFSET(_field) \
  57. ((char *)(&(dummy->_field)) - (char *)(&(dummy->gprs[0].slot[0])))
  58. #define LSCSA_QW_OFFSET(_field) (LSCSA_BYTE_OFFSET(_field) >> 4)
  59. static inline void set_event_mask(void)
  60. {
  61. unsigned int event_mask = 0;
  62. /* Save, Step 4:
  63. * Restore, Step 1:
  64. * Set the SPU_RdEventMsk channel to zero to mask
  65. * all events.
  66. */
  67. spu_writech(SPU_WrEventMask, event_mask);
  68. }
  69. static inline void set_tag_mask(void)
  70. {
  71. unsigned int tag_mask = 1;
  72. /* Save, Step 5:
  73. * Restore, Step 2:
  74. * Set the SPU_WrTagMsk channel to '01' to unmask
  75. * only tag group 0.
  76. */
  77. spu_writech(MFC_WrTagMask, tag_mask);
  78. }
  79. static inline void build_dma_list(addr64 lscsa_ea)
  80. {
  81. unsigned int ea_low;
  82. int i;
  83. /* Save, Step 6:
  84. * Restore, Step 3:
  85. * Update the effective address for the CSA in the
  86. * pre-canned DMA-list in local storage.
  87. */
  88. ea_low = lscsa_ea.ui[1];
  89. ea_low += LSCSA_BYTE_OFFSET(ls[16384]);
  90. for (i = 0; i < 15; i++, ea_low += 16384) {
  91. dma_list[i].size = 16384;
  92. dma_list[i].ea_low = ea_low;
  93. }
  94. }
  95. static inline void enqueue_putllc(addr64 lscsa_ea)
  96. {
  97. unsigned int ls = 0;
  98. unsigned int size = 128;
  99. unsigned int tag_id = 0;
  100. unsigned int cmd = 0xB4; /* PUTLLC */
  101. /* Save, Step 12:
  102. * Restore, Step 7:
  103. * Send a PUTLLC (tag 0) command to the MFC using
  104. * an effective address in the CSA in order to
  105. * remove any possible lock-line reservation.
  106. */
  107. spu_writech(MFC_LSA, ls);
  108. spu_writech(MFC_EAH, lscsa_ea.ui[0]);
  109. spu_writech(MFC_EAL, lscsa_ea.ui[1]);
  110. spu_writech(MFC_Size, size);
  111. spu_writech(MFC_TagID, tag_id);
  112. spu_writech(MFC_Cmd, cmd);
  113. }
  114. static inline void set_tag_update(void)
  115. {
  116. unsigned int update_any = 1;
  117. /* Save, Step 15:
  118. * Restore, Step 8:
  119. * Write the MFC_TagUpdate channel with '01'.
  120. */
  121. spu_writech(MFC_WrTagUpdate, update_any);
  122. }
  123. static inline void read_tag_status(void)
  124. {
  125. /* Save, Step 16:
  126. * Restore, Step 9:
  127. * Read the MFC_TagStat channel data.
  128. */
  129. spu_readch(MFC_RdTagStat);
  130. }
  131. static inline void read_llar_status(void)
  132. {
  133. /* Save, Step 17:
  134. * Restore, Step 10:
  135. * Read the MFC_AtomicStat channel data.
  136. */
  137. spu_readch(MFC_RdAtomicStat);
  138. }
  139. #endif /* _SPU_CONTEXT_UTILS_H_ */