blob: b75b091098efc4b2739a23e443421e8e81cd99b4 [file] [log] [blame]
Arnd Bergmann67207b92005-11-15 15:53:48 -05001/*
2 * Low-level SPU handling
3 *
4 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
5 *
6 * Author: Arnd Bergmann <arndb@de.ibm.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
Arnd Bergmann3b3d22c2005-12-05 22:52:24 -050023#undef DEBUG
Arnd Bergmann67207b92005-11-15 15:53:48 -050024
25#include <linux/interrupt.h>
26#include <linux/list.h>
27#include <linux/module.h>
Arnd Bergmann7650f2f2006-10-04 17:26:20 +020028#include <linux/pci.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050029#include <linux/poll.h>
30#include <linux/ptrace.h>
31#include <linux/slab.h>
32#include <linux/wait.h>
33
Arnd Bergmann7650f2f2006-10-04 17:26:20 +020034#include <asm/firmware.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050035#include <asm/io.h>
36#include <asm/prom.h>
Ingo Molnar14cc3e22006-03-26 01:37:14 -080037#include <linux/mutex.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050038#include <asm/spu.h>
Geoff Levand540270d2006-06-19 20:33:29 +020039#include <asm/spu_priv1.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050040#include <asm/mmu_context.h>
41
42#include "interrupt.h"
43
Geoff Levand540270d2006-06-19 20:33:29 +020044const struct spu_priv1_ops *spu_priv1_ops;
45
46EXPORT_SYMBOL_GPL(spu_priv1_ops);
47
Arnd Bergmann67207b92005-11-15 15:53:48 -050048static int __spu_trap_invalid_dma(struct spu *spu)
49{
50 pr_debug("%s\n", __FUNCTION__);
Arnd Bergmann9add11d2006-10-04 17:26:14 +020051 spu->dma_callback(spu, SPE_EVENT_INVALID_DMA);
Arnd Bergmann67207b92005-11-15 15:53:48 -050052 return 0;
53}
54
55static int __spu_trap_dma_align(struct spu *spu)
56{
57 pr_debug("%s\n", __FUNCTION__);
Arnd Bergmann9add11d2006-10-04 17:26:14 +020058 spu->dma_callback(spu, SPE_EVENT_DMA_ALIGNMENT);
Arnd Bergmann67207b92005-11-15 15:53:48 -050059 return 0;
60}
61
62static int __spu_trap_error(struct spu *spu)
63{
64 pr_debug("%s\n", __FUNCTION__);
Arnd Bergmann9add11d2006-10-04 17:26:14 +020065 spu->dma_callback(spu, SPE_EVENT_SPE_ERROR);
Arnd Bergmann67207b92005-11-15 15:53:48 -050066 return 0;
67}
68
69static void spu_restart_dma(struct spu *spu)
70{
71 struct spu_priv2 __iomem *priv2 = spu->priv2;
Mark Nutter5473af02005-11-15 15:53:49 -050072
Arnd Bergmann8837d922006-01-04 20:31:28 +010073 if (!test_bit(SPU_CONTEXT_SWITCH_PENDING, &spu->flags))
Mark Nutter5473af02005-11-15 15:53:49 -050074 out_be64(&priv2->mfc_control_RW, MFC_CNTL_RESTART_DMA_COMMAND);
Arnd Bergmann67207b92005-11-15 15:53:48 -050075}
76
77static int __spu_trap_data_seg(struct spu *spu, unsigned long ea)
78{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050079 struct spu_priv2 __iomem *priv2 = spu->priv2;
80 struct mm_struct *mm = spu->mm;
arnd@arndb.de724bd802006-06-19 20:33:23 +020081 u64 esid, vsid, llp;
Arnd Bergmann67207b92005-11-15 15:53:48 -050082
83 pr_debug("%s\n", __FUNCTION__);
84
Arnd Bergmann8837d922006-01-04 20:31:28 +010085 if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050086 /* SLBs are pre-loaded for context switch, so
87 * we should never get here!
88 */
Mark Nutter5473af02005-11-15 15:53:49 -050089 printk("%s: invalid access during switch!\n", __func__);
90 return 1;
91 }
arnd@arndb.de0afacde2006-10-24 18:31:18 +020092 esid = (ea & ESID_MASK) | SLB_ESID_V;
93
94 switch(REGION_ID(ea)) {
95 case USER_REGION_ID:
96#ifdef CONFIG_HUGETLB_PAGE
97 if (in_hugepage_area(mm->context, ea))
98 llp = mmu_psize_defs[mmu_huge_psize].sllp;
99 else
100#endif
101 llp = mmu_psize_defs[mmu_virtual_psize].sllp;
102 vsid = (get_vsid(mm->context.id, ea) << SLB_VSID_SHIFT) |
103 SLB_VSID_USER | llp;
104 break;
105 case VMALLOC_REGION_ID:
106 llp = mmu_psize_defs[mmu_virtual_psize].sllp;
107 vsid = (get_kernel_vsid(ea) << SLB_VSID_SHIFT) |
108 SLB_VSID_KERNEL | llp;
109 break;
110 case KERNEL_REGION_ID:
111 llp = mmu_psize_defs[mmu_linear_psize].sllp;
112 vsid = (get_kernel_vsid(ea) << SLB_VSID_SHIFT) |
113 SLB_VSID_KERNEL | llp;
114 break;
115 default:
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500116 /* Future: support kernel segments so that drivers
117 * can use SPUs.
118 */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500119 pr_debug("invalid region access at %016lx\n", ea);
120 return 1;
121 }
122
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500123 out_be64(&priv2->slb_index_W, spu->slb_replace);
124 out_be64(&priv2->slb_vsid_RW, vsid);
125 out_be64(&priv2->slb_esid_RW, esid);
126
127 spu->slb_replace++;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500128 if (spu->slb_replace >= 8)
129 spu->slb_replace = 0;
130
Arnd Bergmann67207b92005-11-15 15:53:48 -0500131 spu_restart_dma(spu);
132
Arnd Bergmann67207b92005-11-15 15:53:48 -0500133 return 0;
134}
135
Mark Nutter5473af02005-11-15 15:53:49 -0500136extern int hash_page(unsigned long ea, unsigned long access, unsigned long trap); //XXX
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500137static int __spu_trap_data_map(struct spu *spu, unsigned long ea, u64 dsisr)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500138{
Arnd Bergmanna33a7d72006-03-23 00:00:11 +0100139 pr_debug("%s, %lx, %lx\n", __FUNCTION__, dsisr, ea);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500140
Mark Nutter5473af02005-11-15 15:53:49 -0500141 /* Handle kernel space hash faults immediately.
142 User hash faults need to be deferred to process context. */
143 if ((dsisr & MFC_DSISR_PTE_NOT_FOUND)
144 && REGION_ID(ea) != USER_REGION_ID
145 && hash_page(ea, _PAGE_PRESENT, 0x300) == 0) {
146 spu_restart_dma(spu);
147 return 0;
148 }
Arnd Bergmann67207b92005-11-15 15:53:48 -0500149
Arnd Bergmann8837d922006-01-04 20:31:28 +0100150 if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) {
Mark Nutter5473af02005-11-15 15:53:49 -0500151 printk("%s: invalid access during switch!\n", __func__);
152 return 1;
153 }
154
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500155 spu->dar = ea;
156 spu->dsisr = dsisr;
157 mb();
Masato Noguchiba723fe22006-06-19 20:33:33 +0200158 spu->stop_callback(spu);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500159 return 0;
160}
161
162static irqreturn_t
Olaf Heringf5a92452006-10-06 22:52:16 +0200163spu_irq_class_0(int irq, void *data)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500164{
165 struct spu *spu;
166
167 spu = data;
168 spu->class_0_pending = 1;
Masato Noguchiba723fe22006-06-19 20:33:33 +0200169 spu->stop_callback(spu);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500170
171 return IRQ_HANDLED;
172}
173
Arnd Bergmann51104592005-12-05 22:52:25 -0500174int
Arnd Bergmann67207b92005-11-15 15:53:48 -0500175spu_irq_class_0_bottom(struct spu *spu)
176{
Arnd Bergmann3a843d72005-12-05 22:52:27 -0500177 unsigned long stat, mask;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500178
179 spu->class_0_pending = 0;
180
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100181 mask = spu_int_mask_get(spu, 0);
182 stat = spu_int_stat_get(spu, 0);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500183
Arnd Bergmann3a843d72005-12-05 22:52:27 -0500184 stat &= mask;
185
Arnd Bergmann2cd90bc2006-06-23 20:57:50 +0200186 if (stat & 1) /* invalid DMA alignment */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500187 __spu_trap_dma_align(spu);
188
Arnd Bergmann2cd90bc2006-06-23 20:57:50 +0200189 if (stat & 2) /* invalid MFC DMA */
190 __spu_trap_invalid_dma(spu);
191
Arnd Bergmann67207b92005-11-15 15:53:48 -0500192 if (stat & 4) /* error on SPU */
193 __spu_trap_error(spu);
194
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100195 spu_int_stat_clear(spu, 0, stat);
Arnd Bergmann51104592005-12-05 22:52:25 -0500196
197 return (stat & 0x7) ? -EIO : 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500198}
Arnd Bergmann51104592005-12-05 22:52:25 -0500199EXPORT_SYMBOL_GPL(spu_irq_class_0_bottom);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500200
201static irqreturn_t
Olaf Heringf5a92452006-10-06 22:52:16 +0200202spu_irq_class_1(int irq, void *data)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500203{
204 struct spu *spu;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500205 unsigned long stat, mask, dar, dsisr;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500206
207 spu = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500208
209 /* atomically read & clear class1 status. */
210 spin_lock(&spu->register_lock);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100211 mask = spu_int_mask_get(spu, 1);
212 stat = spu_int_stat_get(spu, 1) & mask;
213 dar = spu_mfc_dar_get(spu);
214 dsisr = spu_mfc_dsisr_get(spu);
Arnd Bergmann38307342005-12-09 19:04:18 +0100215 if (stat & 2) /* mapping fault */
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100216 spu_mfc_dsisr_set(spu, 0ul);
217 spu_int_stat_clear(spu, 1, stat);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500218 spin_unlock(&spu->register_lock);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +0100219 pr_debug("%s: %lx %lx %lx %lx\n", __FUNCTION__, mask, stat,
220 dar, dsisr);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500221
222 if (stat & 1) /* segment fault */
223 __spu_trap_data_seg(spu, dar);
224
225 if (stat & 2) { /* mapping fault */
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500226 __spu_trap_data_map(spu, dar, dsisr);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500227 }
228
229 if (stat & 4) /* ls compare & suspend on get */
230 ;
231
232 if (stat & 8) /* ls compare & suspend on put */
233 ;
234
Arnd Bergmann67207b92005-11-15 15:53:48 -0500235 return stat ? IRQ_HANDLED : IRQ_NONE;
236}
Arnd Bergmann51104592005-12-05 22:52:25 -0500237EXPORT_SYMBOL_GPL(spu_irq_class_1_bottom);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500238
239static irqreturn_t
Olaf Heringf5a92452006-10-06 22:52:16 +0200240spu_irq_class_2(int irq, void *data)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500241{
242 struct spu *spu;
243 unsigned long stat;
Arnd Bergmann3a843d72005-12-05 22:52:27 -0500244 unsigned long mask;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500245
246 spu = data;
Masato Noguchiba723fe22006-06-19 20:33:33 +0200247 spin_lock(&spu->register_lock);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100248 stat = spu_int_stat_get(spu, 2);
249 mask = spu_int_mask_get(spu, 2);
Masato Noguchiba723fe22006-06-19 20:33:33 +0200250 /* ignore interrupts we're not waiting for */
251 stat &= mask;
252 /*
253 * mailbox interrupts (0x1 and 0x10) are level triggered.
254 * mask them now before acknowledging.
255 */
256 if (stat & 0x11)
257 spu_int_mask_and(spu, 2, ~(stat & 0x11));
258 /* acknowledge all interrupts before the callbacks */
259 spu_int_stat_clear(spu, 2, stat);
260 spin_unlock(&spu->register_lock);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500261
Arnd Bergmann3a843d72005-12-05 22:52:27 -0500262 pr_debug("class 2 interrupt %d, %lx, %lx\n", irq, stat, mask);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500263
Arnd Bergmann67207b92005-11-15 15:53:48 -0500264 if (stat & 1) /* PPC core mailbox */
Masato Noguchiba723fe22006-06-19 20:33:33 +0200265 spu->ibox_callback(spu);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500266
267 if (stat & 2) /* SPU stop-and-signal */
Masato Noguchiba723fe22006-06-19 20:33:33 +0200268 spu->stop_callback(spu);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500269
270 if (stat & 4) /* SPU halted */
Masato Noguchiba723fe22006-06-19 20:33:33 +0200271 spu->stop_callback(spu);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500272
273 if (stat & 8) /* DMA tag group complete */
Masato Noguchiba723fe22006-06-19 20:33:33 +0200274 spu->mfc_callback(spu);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500275
276 if (stat & 0x10) /* SPU mailbox threshold */
Masato Noguchiba723fe22006-06-19 20:33:33 +0200277 spu->wbox_callback(spu);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500278
Arnd Bergmann67207b92005-11-15 15:53:48 -0500279 return stat ? IRQ_HANDLED : IRQ_NONE;
280}
281
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000282static int spu_request_irqs(struct spu *spu)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500283{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000284 int ret = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500285
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000286 if (spu->irqs[0] != NO_IRQ) {
287 snprintf(spu->irq_c0, sizeof (spu->irq_c0), "spe%02d.0",
288 spu->number);
289 ret = request_irq(spu->irqs[0], spu_irq_class_0,
290 IRQF_DISABLED,
291 spu->irq_c0, spu);
292 if (ret)
293 goto bail0;
294 }
295 if (spu->irqs[1] != NO_IRQ) {
296 snprintf(spu->irq_c1, sizeof (spu->irq_c1), "spe%02d.1",
297 spu->number);
298 ret = request_irq(spu->irqs[1], spu_irq_class_1,
299 IRQF_DISABLED,
300 spu->irq_c1, spu);
301 if (ret)
302 goto bail1;
303 }
304 if (spu->irqs[2] != NO_IRQ) {
305 snprintf(spu->irq_c2, sizeof (spu->irq_c2), "spe%02d.2",
306 spu->number);
307 ret = request_irq(spu->irqs[2], spu_irq_class_2,
308 IRQF_DISABLED,
309 spu->irq_c2, spu);
310 if (ret)
311 goto bail2;
312 }
313 return 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500314
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000315bail2:
316 if (spu->irqs[1] != NO_IRQ)
317 free_irq(spu->irqs[1], spu);
318bail1:
319 if (spu->irqs[0] != NO_IRQ)
320 free_irq(spu->irqs[0], spu);
321bail0:
Arnd Bergmann67207b92005-11-15 15:53:48 -0500322 return ret;
323}
324
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000325static void spu_free_irqs(struct spu *spu)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500326{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000327 if (spu->irqs[0] != NO_IRQ)
328 free_irq(spu->irqs[0], spu);
329 if (spu->irqs[1] != NO_IRQ)
330 free_irq(spu->irqs[1], spu);
331 if (spu->irqs[2] != NO_IRQ)
332 free_irq(spu->irqs[2], spu);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500333}
334
Mark Nuttera68cf982006-10-04 17:26:12 +0200335static struct list_head spu_list[MAX_NUMNODES];
Christian Kraffte570beb2006-10-24 18:31:23 +0200336static LIST_HEAD(spu_full_list);
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800337static DEFINE_MUTEX(spu_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500338
339static void spu_init_channels(struct spu *spu)
340{
341 static const struct {
342 unsigned channel;
343 unsigned count;
344 } zero_list[] = {
345 { 0x00, 1, }, { 0x01, 1, }, { 0x03, 1, }, { 0x04, 1, },
346 { 0x18, 1, }, { 0x19, 1, }, { 0x1b, 1, }, { 0x1d, 1, },
347 }, count_list[] = {
348 { 0x00, 0, }, { 0x03, 0, }, { 0x04, 0, }, { 0x15, 16, },
349 { 0x17, 1, }, { 0x18, 0, }, { 0x19, 0, }, { 0x1b, 0, },
350 { 0x1c, 1, }, { 0x1d, 0, }, { 0x1e, 1, },
351 };
Arnd Bergmann6ff730c2006-01-04 20:31:31 +0100352 struct spu_priv2 __iomem *priv2;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500353 int i;
354
355 priv2 = spu->priv2;
356
357 /* initialize all channel data to zero */
358 for (i = 0; i < ARRAY_SIZE(zero_list); i++) {
359 int count;
360
361 out_be64(&priv2->spu_chnlcntptr_RW, zero_list[i].channel);
362 for (count = 0; count < zero_list[i].count; count++)
363 out_be64(&priv2->spu_chnldata_RW, 0);
364 }
365
366 /* initialize channel counts to meaningful values */
367 for (i = 0; i < ARRAY_SIZE(count_list); i++) {
368 out_be64(&priv2->spu_chnlcntptr_RW, count_list[i].channel);
369 out_be64(&priv2->spu_chnlcnt_RW, count_list[i].count);
370 }
371}
372
Mark Nuttera68cf982006-10-04 17:26:12 +0200373struct spu *spu_alloc_node(int node)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500374{
Mark Nuttera68cf982006-10-04 17:26:12 +0200375 struct spu *spu = NULL;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500376
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800377 mutex_lock(&spu_mutex);
Mark Nuttera68cf982006-10-04 17:26:12 +0200378 if (!list_empty(&spu_list[node])) {
379 spu = list_entry(spu_list[node].next, struct spu, list);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500380 list_del_init(&spu->list);
Geoff Levandcc21a662006-10-24 18:31:15 +0200381 pr_debug("Got SPU %d %d\n", spu->number, spu->node);
Mark Nuttera68cf982006-10-04 17:26:12 +0200382 spu_init_channels(spu);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500383 }
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800384 mutex_unlock(&spu_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500385
Mark Nuttera68cf982006-10-04 17:26:12 +0200386 return spu;
387}
388EXPORT_SYMBOL_GPL(spu_alloc_node);
389
390struct spu *spu_alloc(void)
391{
392 struct spu *spu = NULL;
393 int node;
394
395 for (node = 0; node < MAX_NUMNODES; node++) {
396 spu = spu_alloc_node(node);
397 if (spu)
398 break;
399 }
Arnd Bergmann67207b92005-11-15 15:53:48 -0500400
401 return spu;
402}
Arnd Bergmann67207b92005-11-15 15:53:48 -0500403
404void spu_free(struct spu *spu)
405{
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800406 mutex_lock(&spu_mutex);
Mark Nuttera68cf982006-10-04 17:26:12 +0200407 list_add_tail(&spu->list, &spu_list[spu->node]);
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800408 mutex_unlock(&spu_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500409}
Arnd Bergmann39c73c32005-12-05 22:52:21 -0500410EXPORT_SYMBOL_GPL(spu_free);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500411
Arnd Bergmann67207b92005-11-15 15:53:48 -0500412static int spu_handle_mm_fault(struct spu *spu)
413{
Arnd Bergmann67207b92005-11-15 15:53:48 -0500414 struct mm_struct *mm = spu->mm;
415 struct vm_area_struct *vma;
416 u64 ea, dsisr, is_write;
417 int ret;
418
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500419 ea = spu->dar;
420 dsisr = spu->dsisr;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500421#if 0
422 if (!IS_VALID_EA(ea)) {
423 return -EFAULT;
424 }
425#endif /* XXX */
426 if (mm == NULL) {
427 return -EFAULT;
428 }
429 if (mm->pgd == NULL) {
430 return -EFAULT;
431 }
432
433 down_read(&mm->mmap_sem);
434 vma = find_vma(mm, ea);
435 if (!vma)
436 goto bad_area;
437 if (vma->vm_start <= ea)
438 goto good_area;
439 if (!(vma->vm_flags & VM_GROWSDOWN))
440 goto bad_area;
441#if 0
442 if (expand_stack(vma, ea))
443 goto bad_area;
444#endif /* XXX */
445good_area:
446 is_write = dsisr & MFC_DSISR_ACCESS_PUT;
447 if (is_write) {
448 if (!(vma->vm_flags & VM_WRITE))
449 goto bad_area;
450 } else {
451 if (dsisr & MFC_DSISR_ACCESS_DENIED)
452 goto bad_area;
453 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
454 goto bad_area;
455 }
456 ret = 0;
457 switch (handle_mm_fault(mm, vma, ea, is_write)) {
458 case VM_FAULT_MINOR:
459 current->min_flt++;
460 break;
461 case VM_FAULT_MAJOR:
462 current->maj_flt++;
463 break;
464 case VM_FAULT_SIGBUS:
465 ret = -EFAULT;
466 goto bad_area;
467 case VM_FAULT_OOM:
468 ret = -ENOMEM;
469 goto bad_area;
470 default:
471 BUG();
472 }
473 up_read(&mm->mmap_sem);
474 return ret;
475
476bad_area:
477 up_read(&mm->mmap_sem);
478 return -EFAULT;
479}
480
Arnd Bergmann51104592005-12-05 22:52:25 -0500481int spu_irq_class_1_bottom(struct spu *spu)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500482{
Arnd Bergmann67207b92005-11-15 15:53:48 -0500483 u64 ea, dsisr, access, error = 0UL;
484 int ret = 0;
485
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500486 ea = spu->dar;
487 dsisr = spu->dsisr;
Arnd Bergmann79c227a2006-03-24 19:49:27 +0100488 if (dsisr & (MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED)) {
Arnd Bergmannf8072212006-04-29 02:40:21 +0200489 u64 flags;
490
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500491 access = (_PAGE_PRESENT | _PAGE_USER);
492 access |= (dsisr & MFC_DSISR_ACCESS_PUT) ? _PAGE_RW : 0UL;
Arnd Bergmannf8072212006-04-29 02:40:21 +0200493 local_irq_save(flags);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500494 if (hash_page(ea, access, 0x300) != 0)
495 error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
Arnd Bergmannf8072212006-04-29 02:40:21 +0200496 local_irq_restore(flags);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500497 }
Arnd Bergmann79c227a2006-03-24 19:49:27 +0100498 if (error & CLASS1_ENABLE_STORAGE_FAULT_INTR) {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500499 if ((ret = spu_handle_mm_fault(spu)) != 0)
500 error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
501 else
502 error &= ~CLASS1_ENABLE_STORAGE_FAULT_INTR;
503 }
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500504 spu->dar = 0UL;
505 spu->dsisr = 0UL;
506 if (!error) {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500507 spu_restart_dma(spu);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500508 } else {
509 __spu_trap_invalid_dma(spu);
510 }
Arnd Bergmann67207b92005-11-15 15:53:48 -0500511 return ret;
512}
513
Joel H Schoppbed120c2006-05-01 12:16:11 -0700514static int __init find_spu_node_id(struct device_node *spe)
515{
Jeremy Kerrc61c27d2006-07-12 15:39:54 +1000516 const unsigned int *id;
Joel H Schoppbed120c2006-05-01 12:16:11 -0700517 struct device_node *cpu;
518 cpu = spe->parent->parent;
Jeremy Kerrc61c27d2006-07-12 15:39:54 +1000519 id = get_property(cpu, "node-id", NULL);
Joel H Schoppbed120c2006-05-01 12:16:11 -0700520 return id ? *id : 0;
521}
522
Jeremy Kerr8261aa62006-05-01 12:16:13 -0700523static int __init cell_spuprop_present(struct spu *spu, struct device_node *spe,
524 const char *prop)
Joel H Schoppbed120c2006-05-01 12:16:11 -0700525{
526 static DEFINE_MUTEX(add_spumem_mutex);
527
Jeremy Kerrc61c27d2006-07-12 15:39:54 +1000528 const struct address_prop {
Joel H Schoppbed120c2006-05-01 12:16:11 -0700529 unsigned long address;
530 unsigned int len;
531 } __attribute__((packed)) *p;
532 int proplen;
533
534 unsigned long start_pfn, nr_pages;
Joel H Schoppbed120c2006-05-01 12:16:11 -0700535 struct pglist_data *pgdata;
536 struct zone *zone;
537 int ret;
538
Jeremy Kerrc61c27d2006-07-12 15:39:54 +1000539 p = get_property(spe, prop, &proplen);
Joel H Schoppbed120c2006-05-01 12:16:11 -0700540 WARN_ON(proplen != sizeof (*p));
541
542 start_pfn = p->address >> PAGE_SHIFT;
543 nr_pages = ((unsigned long)p->len + PAGE_SIZE - 1) >> PAGE_SHIFT;
544
Jeremy Kerr8261aa62006-05-01 12:16:13 -0700545 pgdata = NODE_DATA(spu->nid);
Joel H Schoppbed120c2006-05-01 12:16:11 -0700546 zone = pgdata->node_zones;
547
548 /* XXX rethink locking here */
549 mutex_lock(&add_spumem_mutex);
550 ret = __add_pages(zone, start_pfn, nr_pages);
551 mutex_unlock(&add_spumem_mutex);
552
553 return ret;
554}
555
Jeremy Kerr8261aa62006-05-01 12:16:13 -0700556static void __iomem * __init map_spe_prop(struct spu *spu,
557 struct device_node *n, const char *name)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500558{
Jeremy Kerrc61c27d2006-07-12 15:39:54 +1000559 const struct address_prop {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500560 unsigned long address;
561 unsigned int len;
562 } __attribute__((packed)) *prop;
563
Jeremy Kerrc61c27d2006-07-12 15:39:54 +1000564 const void *p;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500565 int proplen;
Al Viroed2bfcd2006-09-23 01:37:41 +0100566 void __iomem *ret = NULL;
Joel H Schoppbed120c2006-05-01 12:16:11 -0700567 int err = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500568
569 p = get_property(n, name, &proplen);
570 if (proplen != sizeof (struct address_prop))
571 return NULL;
572
573 prop = p;
574
Jeremy Kerr8261aa62006-05-01 12:16:13 -0700575 err = cell_spuprop_present(spu, n, name);
Joel H Schoppbed120c2006-05-01 12:16:11 -0700576 if (err && (err != -EEXIST))
577 goto out;
578
579 ret = ioremap(prop->address, prop->len);
580
581 out:
582 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500583}
584
585static void spu_unmap(struct spu *spu)
586{
587 iounmap(spu->priv2);
588 iounmap(spu->priv1);
589 iounmap(spu->problem);
Al Viroed2bfcd2006-09-23 01:37:41 +0100590 iounmap((__force u8 __iomem *)spu->local_store);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500591}
592
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000593/* This function shall be abstracted for HV platforms */
Arnd Bergmann7650f2f2006-10-04 17:26:20 +0200594static int __init spu_map_interrupts_old(struct spu *spu, struct device_node *np)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000595{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000596 unsigned int isrc;
Jeremy Kerrc61c27d2006-07-12 15:39:54 +1000597 const u32 *tmp;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000598
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000599 /* Get the interrupt source unit from the device-tree */
Jeremy Kerrc61c27d2006-07-12 15:39:54 +1000600 tmp = get_property(np, "isrc", NULL);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000601 if (!tmp)
602 return -ENODEV;
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000603 isrc = tmp[0];
604
605 /* Add the node number */
606 isrc |= spu->node << IIC_IRQ_NODE_SHIFT;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000607
608 /* Now map interrupts of all 3 classes */
Benjamin Herrenschmidt2e194582006-09-29 15:00:29 +1000609 spu->irqs[0] = irq_create_mapping(NULL, IIC_IRQ_CLASS_0 | isrc);
610 spu->irqs[1] = irq_create_mapping(NULL, IIC_IRQ_CLASS_1 | isrc);
611 spu->irqs[2] = irq_create_mapping(NULL, IIC_IRQ_CLASS_2 | isrc);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000612
613 /* Right now, we only fail if class 2 failed */
614 return spu->irqs[2] == NO_IRQ ? -EINVAL : 0;
615}
616
Arnd Bergmann7650f2f2006-10-04 17:26:20 +0200617static int __init spu_map_device_old(struct spu *spu, struct device_node *node)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500618{
Jeremy Kerrc61c27d2006-07-12 15:39:54 +1000619 const char *prop;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500620 int ret;
621
622 ret = -ENODEV;
Jeremy Kerr8261aa62006-05-01 12:16:13 -0700623 spu->name = get_property(node, "name", NULL);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500624 if (!spu->name)
625 goto out;
626
Jeremy Kerr8261aa62006-05-01 12:16:13 -0700627 prop = get_property(node, "local-store", NULL);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500628 if (!prop)
629 goto out;
630 spu->local_store_phys = *(unsigned long *)prop;
631
632 /* we use local store as ram, not io memory */
Jeremy Kerr8261aa62006-05-01 12:16:13 -0700633 spu->local_store = (void __force *)
634 map_spe_prop(spu, node, "local-store");
Arnd Bergmann67207b92005-11-15 15:53:48 -0500635 if (!spu->local_store)
636 goto out;
637
Jeremy Kerr8261aa62006-05-01 12:16:13 -0700638 prop = get_property(node, "problem", NULL);
Mark Nutter6df10a82006-03-23 00:00:12 +0100639 if (!prop)
640 goto out_unmap;
641 spu->problem_phys = *(unsigned long *)prop;
642
Jeremy Kerr8261aa62006-05-01 12:16:13 -0700643 spu->problem= map_spe_prop(spu, node, "problem");
Arnd Bergmann67207b92005-11-15 15:53:48 -0500644 if (!spu->problem)
645 goto out_unmap;
646
Jeremy Kerr8261aa62006-05-01 12:16:13 -0700647 spu->priv1= map_spe_prop(spu, node, "priv1");
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100648 /* priv1 is not available on a hypervisor */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500649
Jeremy Kerr8261aa62006-05-01 12:16:13 -0700650 spu->priv2= map_spe_prop(spu, node, "priv2");
Arnd Bergmann67207b92005-11-15 15:53:48 -0500651 if (!spu->priv2)
652 goto out_unmap;
653 ret = 0;
654 goto out;
655
656out_unmap:
657 spu_unmap(spu);
658out:
659 return ret;
660}
661
Arnd Bergmann7650f2f2006-10-04 17:26:20 +0200662static int __init spu_map_interrupts(struct spu *spu, struct device_node *np)
663{
664 struct of_irq oirq;
665 int ret;
666 int i;
667
668 for (i=0; i < 3; i++) {
669 ret = of_irq_map_one(np, i, &oirq);
670 if (ret)
671 goto err;
672
673 ret = -EINVAL;
674 spu->irqs[i] = irq_create_of_mapping(oirq.controller,
675 oirq.specifier, oirq.size);
676 if (spu->irqs[i] == NO_IRQ)
677 goto err;
678 }
679 return 0;
680
681err:
682 pr_debug("failed to map irq %x for spu %s\n", *oirq.specifier, spu->name);
683 for (; i >= 0; i--) {
684 if (spu->irqs[i] != NO_IRQ)
685 irq_dispose_mapping(spu->irqs[i]);
686 }
687 return ret;
688}
689
690static int spu_map_resource(struct device_node *node, int nr,
691 void __iomem** virt, unsigned long *phys)
692{
693 struct resource resource = { };
694 int ret;
695
696 ret = of_address_to_resource(node, 0, &resource);
697 if (ret)
698 goto out;
699
700 if (phys)
701 *phys = resource.start;
702 *virt = ioremap(resource.start, resource.end - resource.start);
703 if (!*virt)
704 ret = -EINVAL;
705
706out:
707 return ret;
708}
709
710static int __init spu_map_device(struct spu *spu, struct device_node *node)
711{
712 int ret = -ENODEV;
713 spu->name = get_property(node, "name", NULL);
714 if (!spu->name)
715 goto out;
716
717 ret = spu_map_resource(node, 0, (void __iomem**)&spu->local_store,
718 &spu->local_store_phys);
719 if (ret)
720 goto out;
721 ret = spu_map_resource(node, 1, (void __iomem**)&spu->problem,
722 &spu->problem_phys);
723 if (ret)
724 goto out_unmap;
725 ret = spu_map_resource(node, 2, (void __iomem**)&spu->priv2,
726 NULL);
727 if (ret)
728 goto out_unmap;
729
730 if (!firmware_has_feature(FW_FEATURE_LPAR))
731 ret = spu_map_resource(node, 3, (void __iomem**)&spu->priv1,
732 NULL);
733 if (ret)
734 goto out_unmap;
735 return 0;
736
737out_unmap:
738 spu_unmap(spu);
739out:
740 pr_debug("failed to map spe %s: %d\n", spu->name, ret);
741 return ret;
742}
743
Jeremy Kerr1d640932006-06-19 20:33:19 +0200744struct sysdev_class spu_sysdev_class = {
745 set_kset_name("spu")
746};
747
Christian Kraffte570beb2006-10-24 18:31:23 +0200748int spu_add_sysdev_attr(struct sysdev_attribute *attr)
749{
750 struct spu *spu;
751 mutex_lock(&spu_mutex);
752
753 list_for_each_entry(spu, &spu_full_list, full_list)
754 sysdev_create_file(&spu->sysdev, attr);
755
756 mutex_unlock(&spu_mutex);
757 return 0;
758}
759EXPORT_SYMBOL_GPL(spu_add_sysdev_attr);
760
761int spu_add_sysdev_attr_group(struct attribute_group *attrs)
762{
763 struct spu *spu;
764 mutex_lock(&spu_mutex);
765
766 list_for_each_entry(spu, &spu_full_list, full_list)
767 sysfs_create_group(&spu->sysdev.kobj, attrs);
768
769 mutex_unlock(&spu_mutex);
770 return 0;
771}
772EXPORT_SYMBOL_GPL(spu_add_sysdev_attr_group);
773
774
775void spu_remove_sysdev_attr(struct sysdev_attribute *attr)
776{
777 struct spu *spu;
778 mutex_lock(&spu_mutex);
779
780 list_for_each_entry(spu, &spu_full_list, full_list)
781 sysdev_remove_file(&spu->sysdev, attr);
782
783 mutex_unlock(&spu_mutex);
784}
785EXPORT_SYMBOL_GPL(spu_remove_sysdev_attr);
786
787void spu_remove_sysdev_attr_group(struct attribute_group *attrs)
788{
789 struct spu *spu;
790 mutex_lock(&spu_mutex);
791
792 list_for_each_entry(spu, &spu_full_list, full_list)
793 sysfs_remove_group(&spu->sysdev.kobj, attrs);
794
795 mutex_unlock(&spu_mutex);
796}
797EXPORT_SYMBOL_GPL(spu_remove_sysdev_attr_group);
798
Jeremy Kerr1d640932006-06-19 20:33:19 +0200799static int spu_create_sysdev(struct spu *spu)
800{
801 int ret;
802
803 spu->sysdev.id = spu->number;
804 spu->sysdev.cls = &spu_sysdev_class;
805 ret = sysdev_register(&spu->sysdev);
806 if (ret) {
807 printk(KERN_ERR "Can't register SPU %d with sysfs\n",
808 spu->number);
809 return ret;
810 }
811
Jeremy Kerr1d640932006-06-19 20:33:19 +0200812 sysfs_add_device_to_node(&spu->sysdev, spu->nid);
813
814 return 0;
815}
816
817static void spu_destroy_sysdev(struct spu *spu)
818{
Jeremy Kerr1d640932006-06-19 20:33:19 +0200819 sysfs_remove_device_from_node(&spu->sysdev, spu->nid);
820 sysdev_unregister(&spu->sysdev);
821}
822
Arnd Bergmann67207b92005-11-15 15:53:48 -0500823static int __init create_spu(struct device_node *spe)
824{
825 struct spu *spu;
826 int ret;
827 static int number;
828
829 ret = -ENOMEM;
Jeremy Kerrecec2172006-06-19 20:33:26 +0200830 spu = kzalloc(sizeof (*spu), GFP_KERNEL);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500831 if (!spu)
832 goto out;
833
Benjamin Herrenschmidte5267b42006-10-10 15:14:12 +1000834 spu->node = find_spu_node_id(spe);
835 if (spu->node >= MAX_NUMNODES) {
836 printk(KERN_WARNING "SPE %s on node %d ignored,"
837 " node number too big\n", spe->full_name, spu->node);
838 printk(KERN_WARNING "Check if CONFIG_NUMA is enabled.\n");
839 return -ENODEV;
840 }
841 spu->nid = of_node_to_nid(spe);
842 if (spu->nid == -1)
843 spu->nid = 0;
844
Arnd Bergmann67207b92005-11-15 15:53:48 -0500845 ret = spu_map_device(spu, spe);
Arnd Bergmann7650f2f2006-10-04 17:26:20 +0200846 /* try old method */
847 if (ret)
848 ret = spu_map_device_old(spu, spe);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500849 if (ret)
850 goto out_free;
851
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000852 ret = spu_map_interrupts(spu, spe);
853 if (ret)
Arnd Bergmann7650f2f2006-10-04 17:26:20 +0200854 ret = spu_map_interrupts_old(spu, spe);
855 if (ret)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000856 goto out_unmap;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500857 spin_lock_init(&spu->register_lock);
Masato Noguchi24f43b32006-10-24 18:31:14 +0200858 spu_mfc_sdr_setup(spu);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100859 spu_mfc_sr1_set(spu, 0x33);
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800860 mutex_lock(&spu_mutex);
Jeremy Kerrecec2172006-06-19 20:33:26 +0200861
Arnd Bergmann67207b92005-11-15 15:53:48 -0500862 spu->number = number++;
863 ret = spu_request_irqs(spu);
864 if (ret)
Arnd Bergmann7650f2f2006-10-04 17:26:20 +0200865 goto out_unlock;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500866
Jeremy Kerr1d640932006-06-19 20:33:19 +0200867 ret = spu_create_sysdev(spu);
868 if (ret)
869 goto out_free_irqs;
870
Mark Nuttera68cf982006-10-04 17:26:12 +0200871 list_add(&spu->list, &spu_list[spu->node]);
Christian Kraffte570beb2006-10-24 18:31:23 +0200872 list_add(&spu->full_list, &spu_full_list);
873 spu->devnode = of_node_get(spe);
874
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800875 mutex_unlock(&spu_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500876
Geoff Levandcc21a662006-10-24 18:31:15 +0200877 pr_debug(KERN_DEBUG "Using SPE %s %p %p %p %p %d\n",
878 spu->name, spu->local_store,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500879 spu->problem, spu->priv1, spu->priv2, spu->number);
880 goto out;
881
Jeremy Kerr1d640932006-06-19 20:33:19 +0200882out_free_irqs:
883 spu_free_irqs(spu);
Arnd Bergmann7650f2f2006-10-04 17:26:20 +0200884out_unlock:
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800885 mutex_unlock(&spu_mutex);
Arnd Bergmann7650f2f2006-10-04 17:26:20 +0200886out_unmap:
Arnd Bergmann67207b92005-11-15 15:53:48 -0500887 spu_unmap(spu);
888out_free:
889 kfree(spu);
890out:
891 return ret;
892}
893
894static void destroy_spu(struct spu *spu)
895{
896 list_del_init(&spu->list);
Christian Kraffte570beb2006-10-24 18:31:23 +0200897 list_del_init(&spu->full_list);
898
899 of_node_put(spu->devnode);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500900
Jeremy Kerr1d640932006-06-19 20:33:19 +0200901 spu_destroy_sysdev(spu);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500902 spu_free_irqs(spu);
903 spu_unmap(spu);
904 kfree(spu);
905}
906
907static void cleanup_spu_base(void)
908{
909 struct spu *spu, *tmp;
Mark Nuttera68cf982006-10-04 17:26:12 +0200910 int node;
911
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800912 mutex_lock(&spu_mutex);
Mark Nuttera68cf982006-10-04 17:26:12 +0200913 for (node = 0; node < MAX_NUMNODES; node++) {
914 list_for_each_entry_safe(spu, tmp, &spu_list[node], list)
915 destroy_spu(spu);
916 }
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800917 mutex_unlock(&spu_mutex);
Jeremy Kerr1d640932006-06-19 20:33:19 +0200918 sysdev_class_unregister(&spu_sysdev_class);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500919}
920module_exit(cleanup_spu_base);
921
922static int __init init_spu_base(void)
923{
924 struct device_node *node;
Mark Nuttera68cf982006-10-04 17:26:12 +0200925 int i, ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500926
Jeremy Kerr1d640932006-06-19 20:33:19 +0200927 /* create sysdev class for spus */
928 ret = sysdev_class_register(&spu_sysdev_class);
929 if (ret)
930 return ret;
931
Mark Nuttera68cf982006-10-04 17:26:12 +0200932 for (i = 0; i < MAX_NUMNODES; i++)
933 INIT_LIST_HEAD(&spu_list[i]);
934
Arnd Bergmann67207b92005-11-15 15:53:48 -0500935 ret = -ENODEV;
936 for (node = of_find_node_by_type(NULL, "spe");
937 node; node = of_find_node_by_type(node, "spe")) {
938 ret = create_spu(node);
939 if (ret) {
940 printk(KERN_WARNING "%s: Error initializing %s\n",
941 __FUNCTION__, node->name);
942 cleanup_spu_base();
943 break;
944 }
945 }
Arnd Bergmann67207b92005-11-15 15:53:48 -0500946 return ret;
947}
948module_init(init_spu_base);
949
950MODULE_LICENSE("GPL");
951MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");