1 /* hw_ops.c - query/set operations on active SPU context.
3 * Copyright (C) IBM 2005
4 * Author: Mark Nutter <mnutter@us.ibm.com>
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)
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.
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.
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/errno.h>
24 #include <linux/sched.h>
25 #include <linux/kernel.h>
27 #include <linux/poll.h>
28 #include <linux/smp.h>
29 #include <linux/smp_lock.h>
30 #include <linux/stddef.h>
31 #include <linux/unistd.h>
35 #include <asm/spu_csa.h>
36 #include <asm/mmu_context.h>
39 static int spu_hw_mbox_read(struct spu_context *ctx, u32 * data)
41 struct spu *spu = ctx->spu;
42 struct spu_problem __iomem *prob = spu->problem;
46 spin_lock_irq(&spu->register_lock);
47 mbox_stat = in_be32(&prob->mb_stat_R);
48 if (mbox_stat & 0x0000ff) {
49 *data = in_be32(&prob->pu_mb_R);
52 spin_unlock_irq(&spu->register_lock);
56 static u32 spu_hw_mbox_stat_read(struct spu_context *ctx)
58 return in_be32(&ctx->spu->problem->mb_stat_R);
61 static unsigned int spu_hw_mbox_stat_poll(struct spu_context *ctx,
64 struct spu *spu = ctx->spu;
68 spin_lock_irq(&spu->register_lock);
69 stat = in_be32(&spu->problem->mb_stat_R);
71 /* if the requested event is there, return the poll
72 mask, otherwise enable the interrupt to get notified,
73 but first mark any pending interrupts as done so
74 we don't get woken up unnecessarily */
76 if (events & (POLLIN | POLLRDNORM)) {
78 ret |= POLLIN | POLLRDNORM;
80 spu_int_stat_clear(spu, 2, 0x1);
81 spu_int_mask_or(spu, 2, 0x1);
84 if (events & (POLLOUT | POLLWRNORM)) {
86 ret = POLLOUT | POLLWRNORM;
88 spu_int_stat_clear(spu, 2, 0x10);
89 spu_int_mask_or(spu, 2, 0x10);
92 spin_unlock_irq(&spu->register_lock);
96 static int spu_hw_ibox_read(struct spu_context *ctx, u32 * data)
98 struct spu *spu = ctx->spu;
99 struct spu_problem __iomem *prob = spu->problem;
100 struct spu_priv2 __iomem *priv2 = spu->priv2;
103 spin_lock_irq(&spu->register_lock);
104 if (in_be32(&prob->mb_stat_R) & 0xff0000) {
105 /* read the first available word */
106 *data = in_be64(&priv2->puint_mb_R);
109 /* make sure we get woken up by the interrupt */
110 spu_int_mask_or(spu, 2, 0x1);
113 spin_unlock_irq(&spu->register_lock);
117 static int spu_hw_wbox_write(struct spu_context *ctx, u32 data)
119 struct spu *spu = ctx->spu;
120 struct spu_problem __iomem *prob = spu->problem;
123 spin_lock_irq(&spu->register_lock);
124 if (in_be32(&prob->mb_stat_R) & 0x00ff00) {
125 /* we have space to write wbox_data to */
126 out_be32(&prob->spu_mb_W, data);
129 /* make sure we get woken up by the interrupt when space
131 spu_int_mask_or(spu, 2, 0x10);
134 spin_unlock_irq(&spu->register_lock);
138 static u32 spu_hw_signal1_read(struct spu_context *ctx)
140 return in_be32(&ctx->spu->problem->signal_notify1);
143 static void spu_hw_signal1_write(struct spu_context *ctx, u32 data)
145 out_be32(&ctx->spu->problem->signal_notify1, data);
148 static u32 spu_hw_signal2_read(struct spu_context *ctx)
150 return in_be32(&ctx->spu->problem->signal_notify1);
153 static void spu_hw_signal2_write(struct spu_context *ctx, u32 data)
155 out_be32(&ctx->spu->problem->signal_notify2, data);
158 static void spu_hw_signal1_type_set(struct spu_context *ctx, u64 val)
160 struct spu *spu = ctx->spu;
161 struct spu_priv2 __iomem *priv2 = spu->priv2;
164 spin_lock_irq(&spu->register_lock);
165 tmp = in_be64(&priv2->spu_cfg_RW);
170 out_be64(&priv2->spu_cfg_RW, tmp);
171 spin_unlock_irq(&spu->register_lock);
174 static u64 spu_hw_signal1_type_get(struct spu_context *ctx)
176 return ((in_be64(&ctx->spu->priv2->spu_cfg_RW) & 1) != 0);
179 static void spu_hw_signal2_type_set(struct spu_context *ctx, u64 val)
181 struct spu *spu = ctx->spu;
182 struct spu_priv2 __iomem *priv2 = spu->priv2;
185 spin_lock_irq(&spu->register_lock);
186 tmp = in_be64(&priv2->spu_cfg_RW);
191 out_be64(&priv2->spu_cfg_RW, tmp);
192 spin_unlock_irq(&spu->register_lock);
195 static u64 spu_hw_signal2_type_get(struct spu_context *ctx)
197 return ((in_be64(&ctx->spu->priv2->spu_cfg_RW) & 2) != 0);
200 static u32 spu_hw_npc_read(struct spu_context *ctx)
202 return in_be32(&ctx->spu->problem->spu_npc_RW);
205 static void spu_hw_npc_write(struct spu_context *ctx, u32 val)
207 out_be32(&ctx->spu->problem->spu_npc_RW, val);
210 static u32 spu_hw_status_read(struct spu_context *ctx)
212 return in_be32(&ctx->spu->problem->spu_status_R);
215 static char *spu_hw_get_ls(struct spu_context *ctx)
217 return ctx->spu->local_store;
220 static void spu_hw_runcntl_write(struct spu_context *ctx, u32 val)
223 out_be32(&ctx->spu->problem->spu_runcntl_RW, val);
226 static void spu_hw_runcntl_stop(struct spu_context *ctx)
228 spin_lock_irq(&ctx->spu->register_lock);
229 out_be32(&ctx->spu->problem->spu_runcntl_RW, SPU_RUNCNTL_STOP);
230 while (in_be32(&ctx->spu->problem->spu_status_R) & SPU_STATUS_RUNNING)
232 spin_unlock_irq(&ctx->spu->register_lock);
235 struct spu_context_ops spu_hw_ops = {
236 .mbox_read = spu_hw_mbox_read,
237 .mbox_stat_read = spu_hw_mbox_stat_read,
238 .mbox_stat_poll = spu_hw_mbox_stat_poll,
239 .ibox_read = spu_hw_ibox_read,
240 .wbox_write = spu_hw_wbox_write,
241 .signal1_read = spu_hw_signal1_read,
242 .signal1_write = spu_hw_signal1_write,
243 .signal2_read = spu_hw_signal2_read,
244 .signal2_write = spu_hw_signal2_write,
245 .signal1_type_set = spu_hw_signal1_type_set,
246 .signal1_type_get = spu_hw_signal1_type_get,
247 .signal2_type_set = spu_hw_signal2_type_set,
248 .signal2_type_get = spu_hw_signal2_type_get,
249 .npc_read = spu_hw_npc_read,
250 .npc_write = spu_hw_npc_write,
251 .status_read = spu_hw_status_read,
252 .get_ls = spu_hw_get_ls,
253 .runcntl_write = spu_hw_runcntl_write,
254 .runcntl_stop = spu_hw_runcntl_stop,