hw_ops.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* hw_ops.c - query/set operations on active SPU context.
  2. *
  3. * Copyright (C) IBM 2005
  4. * Author: Mark Nutter <mnutter@us.ibm.com>
  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. #include <linux/config.h>
  21. #include <linux/module.h>
  22. #include <linux/errno.h>
  23. #include <linux/sched.h>
  24. #include <linux/kernel.h>
  25. #include <linux/mm.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/smp.h>
  28. #include <linux/smp_lock.h>
  29. #include <linux/stddef.h>
  30. #include <linux/unistd.h>
  31. #include <asm/io.h>
  32. #include <asm/spu.h>
  33. #include <asm/spu_csa.h>
  34. #include <asm/mmu_context.h>
  35. #include "spufs.h"
  36. static int spu_hw_mbox_read(struct spu_context *ctx, u32 * data)
  37. {
  38. struct spu *spu = ctx->spu;
  39. struct spu_problem __iomem *prob = spu->problem;
  40. u32 mbox_stat;
  41. int ret = 0;
  42. spin_lock_irq(&spu->register_lock);
  43. mbox_stat = in_be32(&prob->mb_stat_R);
  44. if (mbox_stat & 0x0000ff) {
  45. *data = in_be32(&prob->pu_mb_R);
  46. ret = 4;
  47. }
  48. spin_unlock_irq(&spu->register_lock);
  49. return ret;
  50. }
  51. static u32 spu_hw_mbox_stat_read(struct spu_context *ctx)
  52. {
  53. return in_be32(&ctx->spu->problem->mb_stat_R);
  54. }
  55. static int spu_hw_ibox_read(struct spu_context *ctx, u32 * data)
  56. {
  57. struct spu *spu = ctx->spu;
  58. struct spu_problem __iomem *prob = spu->problem;
  59. struct spu_priv1 __iomem *priv1 = spu->priv1;
  60. struct spu_priv2 __iomem *priv2 = spu->priv2;
  61. int ret;
  62. spin_lock_irq(&spu->register_lock);
  63. if (in_be32(&prob->mb_stat_R) & 0xff0000) {
  64. /* read the first available word */
  65. *data = in_be64(&priv2->puint_mb_R);
  66. ret = 4;
  67. } else {
  68. /* make sure we get woken up by the interrupt */
  69. out_be64(&priv1->int_mask_class2_RW,
  70. in_be64(&priv1->int_mask_class2_RW) | 0x1);
  71. ret = 0;
  72. }
  73. spin_unlock_irq(&spu->register_lock);
  74. return ret;
  75. }
  76. static int spu_hw_wbox_write(struct spu_context *ctx, u32 data)
  77. {
  78. struct spu *spu = ctx->spu;
  79. struct spu_problem __iomem *prob = spu->problem;
  80. struct spu_priv1 __iomem *priv1 = spu->priv1;
  81. int ret;
  82. spin_lock_irq(&spu->register_lock);
  83. if (in_be32(&prob->mb_stat_R) & 0x00ff00) {
  84. /* we have space to write wbox_data to */
  85. out_be32(&prob->spu_mb_W, data);
  86. ret = 4;
  87. } else {
  88. /* make sure we get woken up by the interrupt when space
  89. becomes available */
  90. out_be64(&priv1->int_mask_class2_RW,
  91. in_be64(&priv1->int_mask_class2_RW) | 0x10);
  92. ret = 0;
  93. }
  94. spin_unlock_irq(&spu->register_lock);
  95. return ret;
  96. }
  97. static u32 spu_hw_signal1_read(struct spu_context *ctx)
  98. {
  99. return in_be32(&ctx->spu->problem->signal_notify1);
  100. }
  101. static void spu_hw_signal1_write(struct spu_context *ctx, u32 data)
  102. {
  103. out_be32(&ctx->spu->problem->signal_notify1, data);
  104. }
  105. static u32 spu_hw_signal2_read(struct spu_context *ctx)
  106. {
  107. return in_be32(&ctx->spu->problem->signal_notify1);
  108. }
  109. static void spu_hw_signal2_write(struct spu_context *ctx, u32 data)
  110. {
  111. out_be32(&ctx->spu->problem->signal_notify2, data);
  112. }
  113. static void spu_hw_signal1_type_set(struct spu_context *ctx, u64 val)
  114. {
  115. struct spu *spu = ctx->spu;
  116. struct spu_priv2 __iomem *priv2 = spu->priv2;
  117. u64 tmp;
  118. spin_lock_irq(&spu->register_lock);
  119. tmp = in_be64(&priv2->spu_cfg_RW);
  120. if (val)
  121. tmp |= 1;
  122. else
  123. tmp &= ~1;
  124. out_be64(&priv2->spu_cfg_RW, tmp);
  125. spin_unlock_irq(&spu->register_lock);
  126. }
  127. static u64 spu_hw_signal1_type_get(struct spu_context *ctx)
  128. {
  129. return ((in_be64(&ctx->spu->priv2->spu_cfg_RW) & 1) != 0);
  130. }
  131. static void spu_hw_signal2_type_set(struct spu_context *ctx, u64 val)
  132. {
  133. struct spu *spu = ctx->spu;
  134. struct spu_priv2 __iomem *priv2 = spu->priv2;
  135. u64 tmp;
  136. spin_lock_irq(&spu->register_lock);
  137. tmp = in_be64(&priv2->spu_cfg_RW);
  138. if (val)
  139. tmp |= 2;
  140. else
  141. tmp &= ~2;
  142. out_be64(&priv2->spu_cfg_RW, tmp);
  143. spin_unlock_irq(&spu->register_lock);
  144. }
  145. static u64 spu_hw_signal2_type_get(struct spu_context *ctx)
  146. {
  147. return ((in_be64(&ctx->spu->priv2->spu_cfg_RW) & 2) != 0);
  148. }
  149. static u32 spu_hw_npc_read(struct spu_context *ctx)
  150. {
  151. return in_be32(&ctx->spu->problem->spu_npc_RW);
  152. }
  153. static void spu_hw_npc_write(struct spu_context *ctx, u32 val)
  154. {
  155. out_be32(&ctx->spu->problem->spu_npc_RW, val);
  156. }
  157. static u32 spu_hw_status_read(struct spu_context *ctx)
  158. {
  159. return in_be32(&ctx->spu->problem->spu_status_R);
  160. }
  161. static char *spu_hw_get_ls(struct spu_context *ctx)
  162. {
  163. return ctx->spu->local_store;
  164. }
  165. static void spu_hw_runcntl_write(struct spu_context *ctx, u32 val)
  166. {
  167. eieio();
  168. out_be32(&ctx->spu->problem->spu_runcntl_RW, val);
  169. }
  170. static void spu_hw_runcntl_stop(struct spu_context *ctx)
  171. {
  172. spin_lock_irq(&ctx->spu->register_lock);
  173. out_be32(&ctx->spu->problem->spu_runcntl_RW, SPU_RUNCNTL_STOP);
  174. while (in_be32(&ctx->spu->problem->spu_status_R) & SPU_STATUS_RUNNING)
  175. cpu_relax();
  176. spin_unlock_irq(&ctx->spu->register_lock);
  177. }
  178. struct spu_context_ops spu_hw_ops = {
  179. .mbox_read = spu_hw_mbox_read,
  180. .mbox_stat_read = spu_hw_mbox_stat_read,
  181. .ibox_read = spu_hw_ibox_read,
  182. .wbox_write = spu_hw_wbox_write,
  183. .signal1_read = spu_hw_signal1_read,
  184. .signal1_write = spu_hw_signal1_write,
  185. .signal2_read = spu_hw_signal2_read,
  186. .signal2_write = spu_hw_signal2_write,
  187. .signal1_type_set = spu_hw_signal1_type_set,
  188. .signal1_type_get = spu_hw_signal1_type_get,
  189. .signal2_type_set = spu_hw_signal2_type_set,
  190. .signal2_type_get = spu_hw_signal2_type_get,
  191. .npc_read = spu_hw_npc_read,
  192. .npc_write = spu_hw_npc_write,
  193. .status_read = spu_hw_status_read,
  194. .get_ls = spu_hw_get_ls,
  195. .runcntl_write = spu_hw_runcntl_write,
  196. .runcntl_stop = spu_hw_runcntl_stop,
  197. };