spu_base.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  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. #undef DEBUG
  23. #include <linux/interrupt.h>
  24. #include <linux/list.h>
  25. #include <linux/module.h>
  26. #include <linux/poll.h>
  27. #include <linux/ptrace.h>
  28. #include <linux/slab.h>
  29. #include <linux/wait.h>
  30. #include <asm/io.h>
  31. #include <asm/prom.h>
  32. #include <asm/semaphore.h>
  33. #include <asm/spu.h>
  34. #include <asm/mmu_context.h>
  35. #include "interrupt.h"
  36. static int __spu_trap_invalid_dma(struct spu *spu)
  37. {
  38. pr_debug("%s\n", __FUNCTION__);
  39. force_sig(SIGBUS, /* info, */ current);
  40. return 0;
  41. }
  42. static int __spu_trap_dma_align(struct spu *spu)
  43. {
  44. pr_debug("%s\n", __FUNCTION__);
  45. force_sig(SIGBUS, /* info, */ current);
  46. return 0;
  47. }
  48. static int __spu_trap_error(struct spu *spu)
  49. {
  50. pr_debug("%s\n", __FUNCTION__);
  51. force_sig(SIGILL, /* info, */ current);
  52. return 0;
  53. }
  54. static void spu_restart_dma(struct spu *spu)
  55. {
  56. struct spu_priv2 __iomem *priv2 = spu->priv2;
  57. if (!test_bit(SPU_CONTEXT_SWITCH_PENDING_nr, &spu->flags))
  58. out_be64(&priv2->mfc_control_RW, MFC_CNTL_RESTART_DMA_COMMAND);
  59. }
  60. static int __spu_trap_data_seg(struct spu *spu, unsigned long ea)
  61. {
  62. struct spu_priv2 __iomem *priv2 = spu->priv2;
  63. struct mm_struct *mm = spu->mm;
  64. u64 esid, vsid;
  65. pr_debug("%s\n", __FUNCTION__);
  66. if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE_nr, &spu->flags)) {
  67. /* SLBs are pre-loaded for context switch, so
  68. * we should never get here!
  69. */
  70. printk("%s: invalid access during switch!\n", __func__);
  71. return 1;
  72. }
  73. if (!mm || (REGION_ID(ea) != USER_REGION_ID)) {
  74. /* Future: support kernel segments so that drivers
  75. * can use SPUs.
  76. */
  77. pr_debug("invalid region access at %016lx\n", ea);
  78. return 1;
  79. }
  80. esid = (ea & ESID_MASK) | SLB_ESID_V;
  81. vsid = (get_vsid(mm->context.id, ea) << SLB_VSID_SHIFT) | SLB_VSID_USER;
  82. if (in_hugepage_area(mm->context, ea))
  83. vsid |= SLB_VSID_L;
  84. out_be64(&priv2->slb_index_W, spu->slb_replace);
  85. out_be64(&priv2->slb_vsid_RW, vsid);
  86. out_be64(&priv2->slb_esid_RW, esid);
  87. spu->slb_replace++;
  88. if (spu->slb_replace >= 8)
  89. spu->slb_replace = 0;
  90. spu_restart_dma(spu);
  91. return 0;
  92. }
  93. extern int hash_page(unsigned long ea, unsigned long access, unsigned long trap); //XXX
  94. static int __spu_trap_data_map(struct spu *spu, unsigned long ea, u64 dsisr)
  95. {
  96. pr_debug("%s\n", __FUNCTION__);
  97. /* Handle kernel space hash faults immediately.
  98. User hash faults need to be deferred to process context. */
  99. if ((dsisr & MFC_DSISR_PTE_NOT_FOUND)
  100. && REGION_ID(ea) != USER_REGION_ID
  101. && hash_page(ea, _PAGE_PRESENT, 0x300) == 0) {
  102. spu_restart_dma(spu);
  103. return 0;
  104. }
  105. if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE_nr, &spu->flags)) {
  106. printk("%s: invalid access during switch!\n", __func__);
  107. return 1;
  108. }
  109. spu->dar = ea;
  110. spu->dsisr = dsisr;
  111. mb();
  112. if (spu->stop_callback)
  113. spu->stop_callback(spu);
  114. return 0;
  115. }
  116. static int __spu_trap_mailbox(struct spu *spu)
  117. {
  118. if (spu->ibox_callback)
  119. spu->ibox_callback(spu);
  120. /* atomically disable SPU mailbox interrupts */
  121. spin_lock(&spu->register_lock);
  122. out_be64(&spu->priv1->int_mask_class2_RW,
  123. in_be64(&spu->priv1->int_mask_class2_RW) & ~0x1);
  124. spin_unlock(&spu->register_lock);
  125. return 0;
  126. }
  127. static int __spu_trap_stop(struct spu *spu)
  128. {
  129. pr_debug("%s\n", __FUNCTION__);
  130. spu->stop_code = in_be32(&spu->problem->spu_status_R);
  131. if (spu->stop_callback)
  132. spu->stop_callback(spu);
  133. return 0;
  134. }
  135. static int __spu_trap_halt(struct spu *spu)
  136. {
  137. pr_debug("%s\n", __FUNCTION__);
  138. spu->stop_code = in_be32(&spu->problem->spu_status_R);
  139. if (spu->stop_callback)
  140. spu->stop_callback(spu);
  141. return 0;
  142. }
  143. static int __spu_trap_tag_group(struct spu *spu)
  144. {
  145. pr_debug("%s\n", __FUNCTION__);
  146. /* wake_up(&spu->dma_wq); */
  147. return 0;
  148. }
  149. static int __spu_trap_spubox(struct spu *spu)
  150. {
  151. if (spu->wbox_callback)
  152. spu->wbox_callback(spu);
  153. /* atomically disable SPU mailbox interrupts */
  154. spin_lock(&spu->register_lock);
  155. out_be64(&spu->priv1->int_mask_class2_RW,
  156. in_be64(&spu->priv1->int_mask_class2_RW) & ~0x10);
  157. spin_unlock(&spu->register_lock);
  158. return 0;
  159. }
  160. static irqreturn_t
  161. spu_irq_class_0(int irq, void *data, struct pt_regs *regs)
  162. {
  163. struct spu *spu;
  164. spu = data;
  165. spu->class_0_pending = 1;
  166. if (spu->stop_callback)
  167. spu->stop_callback(spu);
  168. return IRQ_HANDLED;
  169. }
  170. int
  171. spu_irq_class_0_bottom(struct spu *spu)
  172. {
  173. unsigned long stat, mask;
  174. spu->class_0_pending = 0;
  175. mask = in_be64(&spu->priv1->int_mask_class0_RW);
  176. stat = in_be64(&spu->priv1->int_stat_class0_RW);
  177. stat &= mask;
  178. if (stat & 1) /* invalid MFC DMA */
  179. __spu_trap_invalid_dma(spu);
  180. if (stat & 2) /* invalid DMA alignment */
  181. __spu_trap_dma_align(spu);
  182. if (stat & 4) /* error on SPU */
  183. __spu_trap_error(spu);
  184. out_be64(&spu->priv1->int_stat_class0_RW, stat);
  185. return (stat & 0x7) ? -EIO : 0;
  186. }
  187. EXPORT_SYMBOL_GPL(spu_irq_class_0_bottom);
  188. static irqreturn_t
  189. spu_irq_class_1(int irq, void *data, struct pt_regs *regs)
  190. {
  191. struct spu *spu;
  192. unsigned long stat, mask, dar, dsisr;
  193. spu = data;
  194. /* atomically read & clear class1 status. */
  195. spin_lock(&spu->register_lock);
  196. mask = in_be64(&spu->priv1->int_mask_class1_RW);
  197. stat = in_be64(&spu->priv1->int_stat_class1_RW) & mask;
  198. dar = in_be64(&spu->priv1->mfc_dar_RW);
  199. dsisr = in_be64(&spu->priv1->mfc_dsisr_RW);
  200. out_be64(&spu->priv1->mfc_dsisr_RW, 0UL);
  201. out_be64(&spu->priv1->int_stat_class1_RW, stat);
  202. spin_unlock(&spu->register_lock);
  203. if (stat & 1) /* segment fault */
  204. __spu_trap_data_seg(spu, dar);
  205. if (stat & 2) { /* mapping fault */
  206. __spu_trap_data_map(spu, dar, dsisr);
  207. }
  208. if (stat & 4) /* ls compare & suspend on get */
  209. ;
  210. if (stat & 8) /* ls compare & suspend on put */
  211. ;
  212. return stat ? IRQ_HANDLED : IRQ_NONE;
  213. }
  214. EXPORT_SYMBOL_GPL(spu_irq_class_1_bottom);
  215. static irqreturn_t
  216. spu_irq_class_2(int irq, void *data, struct pt_regs *regs)
  217. {
  218. struct spu *spu;
  219. unsigned long stat;
  220. unsigned long mask;
  221. spu = data;
  222. stat = in_be64(&spu->priv1->int_stat_class2_RW);
  223. mask = in_be64(&spu->priv1->int_mask_class2_RW);
  224. pr_debug("class 2 interrupt %d, %lx, %lx\n", irq, stat, mask);
  225. stat &= mask;
  226. if (stat & 1) /* PPC core mailbox */
  227. __spu_trap_mailbox(spu);
  228. if (stat & 2) /* SPU stop-and-signal */
  229. __spu_trap_stop(spu);
  230. if (stat & 4) /* SPU halted */
  231. __spu_trap_halt(spu);
  232. if (stat & 8) /* DMA tag group complete */
  233. __spu_trap_tag_group(spu);
  234. if (stat & 0x10) /* SPU mailbox threshold */
  235. __spu_trap_spubox(spu);
  236. out_be64(&spu->priv1->int_stat_class2_RW, stat);
  237. return stat ? IRQ_HANDLED : IRQ_NONE;
  238. }
  239. static int
  240. spu_request_irqs(struct spu *spu)
  241. {
  242. int ret;
  243. int irq_base;
  244. irq_base = IIC_NODE_STRIDE * spu->node + IIC_SPE_OFFSET;
  245. snprintf(spu->irq_c0, sizeof (spu->irq_c0), "spe%02d.0", spu->number);
  246. ret = request_irq(irq_base + spu->isrc,
  247. spu_irq_class_0, 0, spu->irq_c0, spu);
  248. if (ret)
  249. goto out;
  250. out_be64(&spu->priv1->int_mask_class0_RW, 0x7);
  251. snprintf(spu->irq_c1, sizeof (spu->irq_c1), "spe%02d.1", spu->number);
  252. ret = request_irq(irq_base + IIC_CLASS_STRIDE + spu->isrc,
  253. spu_irq_class_1, 0, spu->irq_c1, spu);
  254. if (ret)
  255. goto out1;
  256. out_be64(&spu->priv1->int_mask_class1_RW, 0x3);
  257. snprintf(spu->irq_c2, sizeof (spu->irq_c2), "spe%02d.2", spu->number);
  258. ret = request_irq(irq_base + 2*IIC_CLASS_STRIDE + spu->isrc,
  259. spu_irq_class_2, 0, spu->irq_c2, spu);
  260. if (ret)
  261. goto out2;
  262. out_be64(&spu->priv1->int_mask_class2_RW, 0xe);
  263. goto out;
  264. out2:
  265. free_irq(irq_base + IIC_CLASS_STRIDE + spu->isrc, spu);
  266. out1:
  267. free_irq(irq_base + spu->isrc, spu);
  268. out:
  269. return ret;
  270. }
  271. static void
  272. spu_free_irqs(struct spu *spu)
  273. {
  274. int irq_base;
  275. irq_base = IIC_NODE_STRIDE * spu->node + IIC_SPE_OFFSET;
  276. free_irq(irq_base + spu->isrc, spu);
  277. free_irq(irq_base + IIC_CLASS_STRIDE + spu->isrc, spu);
  278. free_irq(irq_base + 2*IIC_CLASS_STRIDE + spu->isrc, spu);
  279. }
  280. static LIST_HEAD(spu_list);
  281. static DECLARE_MUTEX(spu_mutex);
  282. static void spu_init_channels(struct spu *spu)
  283. {
  284. static const struct {
  285. unsigned channel;
  286. unsigned count;
  287. } zero_list[] = {
  288. { 0x00, 1, }, { 0x01, 1, }, { 0x03, 1, }, { 0x04, 1, },
  289. { 0x18, 1, }, { 0x19, 1, }, { 0x1b, 1, }, { 0x1d, 1, },
  290. }, count_list[] = {
  291. { 0x00, 0, }, { 0x03, 0, }, { 0x04, 0, }, { 0x15, 16, },
  292. { 0x17, 1, }, { 0x18, 0, }, { 0x19, 0, }, { 0x1b, 0, },
  293. { 0x1c, 1, }, { 0x1d, 0, }, { 0x1e, 1, },
  294. };
  295. struct spu_priv2 *priv2;
  296. int i;
  297. priv2 = spu->priv2;
  298. /* initialize all channel data to zero */
  299. for (i = 0; i < ARRAY_SIZE(zero_list); i++) {
  300. int count;
  301. out_be64(&priv2->spu_chnlcntptr_RW, zero_list[i].channel);
  302. for (count = 0; count < zero_list[i].count; count++)
  303. out_be64(&priv2->spu_chnldata_RW, 0);
  304. }
  305. /* initialize channel counts to meaningful values */
  306. for (i = 0; i < ARRAY_SIZE(count_list); i++) {
  307. out_be64(&priv2->spu_chnlcntptr_RW, count_list[i].channel);
  308. out_be64(&priv2->spu_chnlcnt_RW, count_list[i].count);
  309. }
  310. }
  311. static void spu_init_regs(struct spu *spu)
  312. {
  313. out_be64(&spu->priv1->int_mask_class0_RW, 0x7);
  314. out_be64(&spu->priv1->int_mask_class1_RW, 0x3);
  315. out_be64(&spu->priv1->int_mask_class2_RW, 0xe);
  316. }
  317. struct spu *spu_alloc(void)
  318. {
  319. struct spu *spu;
  320. down(&spu_mutex);
  321. if (!list_empty(&spu_list)) {
  322. spu = list_entry(spu_list.next, struct spu, list);
  323. list_del_init(&spu->list);
  324. pr_debug("Got SPU %x %d\n", spu->isrc, spu->number);
  325. } else {
  326. pr_debug("No SPU left\n");
  327. spu = NULL;
  328. }
  329. up(&spu_mutex);
  330. if (spu) {
  331. spu_init_channels(spu);
  332. spu_init_regs(spu);
  333. }
  334. return spu;
  335. }
  336. EXPORT_SYMBOL_GPL(spu_alloc);
  337. void spu_free(struct spu *spu)
  338. {
  339. down(&spu_mutex);
  340. list_add_tail(&spu->list, &spu_list);
  341. up(&spu_mutex);
  342. }
  343. EXPORT_SYMBOL_GPL(spu_free);
  344. static int spu_handle_mm_fault(struct spu *spu)
  345. {
  346. struct mm_struct *mm = spu->mm;
  347. struct vm_area_struct *vma;
  348. u64 ea, dsisr, is_write;
  349. int ret;
  350. ea = spu->dar;
  351. dsisr = spu->dsisr;
  352. #if 0
  353. if (!IS_VALID_EA(ea)) {
  354. return -EFAULT;
  355. }
  356. #endif /* XXX */
  357. if (mm == NULL) {
  358. return -EFAULT;
  359. }
  360. if (mm->pgd == NULL) {
  361. return -EFAULT;
  362. }
  363. down_read(&mm->mmap_sem);
  364. vma = find_vma(mm, ea);
  365. if (!vma)
  366. goto bad_area;
  367. if (vma->vm_start <= ea)
  368. goto good_area;
  369. if (!(vma->vm_flags & VM_GROWSDOWN))
  370. goto bad_area;
  371. #if 0
  372. if (expand_stack(vma, ea))
  373. goto bad_area;
  374. #endif /* XXX */
  375. good_area:
  376. is_write = dsisr & MFC_DSISR_ACCESS_PUT;
  377. if (is_write) {
  378. if (!(vma->vm_flags & VM_WRITE))
  379. goto bad_area;
  380. } else {
  381. if (dsisr & MFC_DSISR_ACCESS_DENIED)
  382. goto bad_area;
  383. if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
  384. goto bad_area;
  385. }
  386. ret = 0;
  387. switch (handle_mm_fault(mm, vma, ea, is_write)) {
  388. case VM_FAULT_MINOR:
  389. current->min_flt++;
  390. break;
  391. case VM_FAULT_MAJOR:
  392. current->maj_flt++;
  393. break;
  394. case VM_FAULT_SIGBUS:
  395. ret = -EFAULT;
  396. goto bad_area;
  397. case VM_FAULT_OOM:
  398. ret = -ENOMEM;
  399. goto bad_area;
  400. default:
  401. BUG();
  402. }
  403. up_read(&mm->mmap_sem);
  404. return ret;
  405. bad_area:
  406. up_read(&mm->mmap_sem);
  407. return -EFAULT;
  408. }
  409. int spu_irq_class_1_bottom(struct spu *spu)
  410. {
  411. u64 ea, dsisr, access, error = 0UL;
  412. int ret = 0;
  413. ea = spu->dar;
  414. dsisr = spu->dsisr;
  415. if (dsisr & MFC_DSISR_PTE_NOT_FOUND) {
  416. access = (_PAGE_PRESENT | _PAGE_USER);
  417. access |= (dsisr & MFC_DSISR_ACCESS_PUT) ? _PAGE_RW : 0UL;
  418. if (hash_page(ea, access, 0x300) != 0)
  419. error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
  420. }
  421. if ((error & CLASS1_ENABLE_STORAGE_FAULT_INTR) ||
  422. (dsisr & MFC_DSISR_ACCESS_DENIED)) {
  423. if ((ret = spu_handle_mm_fault(spu)) != 0)
  424. error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
  425. else
  426. error &= ~CLASS1_ENABLE_STORAGE_FAULT_INTR;
  427. }
  428. spu->dar = 0UL;
  429. spu->dsisr = 0UL;
  430. if (!error) {
  431. spu_restart_dma(spu);
  432. } else {
  433. __spu_trap_invalid_dma(spu);
  434. }
  435. return ret;
  436. }
  437. static void __iomem * __init map_spe_prop(struct device_node *n,
  438. const char *name)
  439. {
  440. struct address_prop {
  441. unsigned long address;
  442. unsigned int len;
  443. } __attribute__((packed)) *prop;
  444. void *p;
  445. int proplen;
  446. p = get_property(n, name, &proplen);
  447. if (proplen != sizeof (struct address_prop))
  448. return NULL;
  449. prop = p;
  450. return ioremap(prop->address, prop->len);
  451. }
  452. static void spu_unmap(struct spu *spu)
  453. {
  454. iounmap(spu->priv2);
  455. iounmap(spu->priv1);
  456. iounmap(spu->problem);
  457. iounmap((u8 __iomem *)spu->local_store);
  458. }
  459. static int __init spu_map_device(struct spu *spu, struct device_node *spe)
  460. {
  461. char *prop;
  462. int ret;
  463. ret = -ENODEV;
  464. prop = get_property(spe, "isrc", NULL);
  465. if (!prop)
  466. goto out;
  467. spu->isrc = *(unsigned int *)prop;
  468. spu->name = get_property(spe, "name", NULL);
  469. if (!spu->name)
  470. goto out;
  471. prop = get_property(spe, "local-store", NULL);
  472. if (!prop)
  473. goto out;
  474. spu->local_store_phys = *(unsigned long *)prop;
  475. /* we use local store as ram, not io memory */
  476. spu->local_store = (void __force *)map_spe_prop(spe, "local-store");
  477. if (!spu->local_store)
  478. goto out;
  479. spu->problem= map_spe_prop(spe, "problem");
  480. if (!spu->problem)
  481. goto out_unmap;
  482. spu->priv1= map_spe_prop(spe, "priv1");
  483. if (!spu->priv1)
  484. goto out_unmap;
  485. spu->priv2= map_spe_prop(spe, "priv2");
  486. if (!spu->priv2)
  487. goto out_unmap;
  488. ret = 0;
  489. goto out;
  490. out_unmap:
  491. spu_unmap(spu);
  492. out:
  493. return ret;
  494. }
  495. static int __init find_spu_node_id(struct device_node *spe)
  496. {
  497. unsigned int *id;
  498. struct device_node *cpu;
  499. cpu = spe->parent->parent;
  500. id = (unsigned int *)get_property(cpu, "node-id", NULL);
  501. return id ? *id : 0;
  502. }
  503. static int __init create_spu(struct device_node *spe)
  504. {
  505. struct spu *spu;
  506. int ret;
  507. static int number;
  508. ret = -ENOMEM;
  509. spu = kmalloc(sizeof (*spu), GFP_KERNEL);
  510. if (!spu)
  511. goto out;
  512. ret = spu_map_device(spu, spe);
  513. if (ret)
  514. goto out_free;
  515. spu->node = find_spu_node_id(spe);
  516. spu->stop_code = 0;
  517. spu->slb_replace = 0;
  518. spu->mm = NULL;
  519. spu->ctx = NULL;
  520. spu->rq = NULL;
  521. spu->pid = 0;
  522. spu->class_0_pending = 0;
  523. spu->flags = 0UL;
  524. spu->dar = 0UL;
  525. spu->dsisr = 0UL;
  526. spin_lock_init(&spu->register_lock);
  527. out_be64(&spu->priv1->mfc_sdr_RW, mfspr(SPRN_SDR1));
  528. out_be64(&spu->priv1->mfc_sr1_RW, 0x33);
  529. spu->ibox_callback = NULL;
  530. spu->wbox_callback = NULL;
  531. spu->stop_callback = NULL;
  532. down(&spu_mutex);
  533. spu->number = number++;
  534. ret = spu_request_irqs(spu);
  535. if (ret)
  536. goto out_unmap;
  537. list_add(&spu->list, &spu_list);
  538. up(&spu_mutex);
  539. pr_debug(KERN_DEBUG "Using SPE %s %02x %p %p %p %p %d\n",
  540. spu->name, spu->isrc, spu->local_store,
  541. spu->problem, spu->priv1, spu->priv2, spu->number);
  542. goto out;
  543. out_unmap:
  544. up(&spu_mutex);
  545. spu_unmap(spu);
  546. out_free:
  547. kfree(spu);
  548. out:
  549. return ret;
  550. }
  551. static void destroy_spu(struct spu *spu)
  552. {
  553. list_del_init(&spu->list);
  554. spu_free_irqs(spu);
  555. spu_unmap(spu);
  556. kfree(spu);
  557. }
  558. static void cleanup_spu_base(void)
  559. {
  560. struct spu *spu, *tmp;
  561. down(&spu_mutex);
  562. list_for_each_entry_safe(spu, tmp, &spu_list, list)
  563. destroy_spu(spu);
  564. up(&spu_mutex);
  565. }
  566. module_exit(cleanup_spu_base);
  567. static int __init init_spu_base(void)
  568. {
  569. struct device_node *node;
  570. int ret;
  571. ret = -ENODEV;
  572. for (node = of_find_node_by_type(NULL, "spe");
  573. node; node = of_find_node_by_type(node, "spe")) {
  574. ret = create_spu(node);
  575. if (ret) {
  576. printk(KERN_WARNING "%s: Error initializing %s\n",
  577. __FUNCTION__, node->name);
  578. cleanup_spu_base();
  579. break;
  580. }
  581. }
  582. /* in some old firmware versions, the spe is called 'spc', so we
  583. look for that as well */
  584. for (node = of_find_node_by_type(NULL, "spc");
  585. node; node = of_find_node_by_type(node, "spc")) {
  586. ret = create_spu(node);
  587. if (ret) {
  588. printk(KERN_WARNING "%s: Error initializing %s\n",
  589. __FUNCTION__, node->name);
  590. cleanup_spu_base();
  591. break;
  592. }
  593. }
  594. return ret;
  595. }
  596. module_init(init_spu_base);
  597. MODULE_LICENSE("GPL");
  598. MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");