spu_base.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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, &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, &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, &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. if (stat & 2) /* mapping fault */
  201. out_be64(&spu->priv1->mfc_dsisr_RW, 0UL);
  202. out_be64(&spu->priv1->int_stat_class1_RW, stat);
  203. spin_unlock(&spu->register_lock);
  204. if (stat & 1) /* segment fault */
  205. __spu_trap_data_seg(spu, dar);
  206. if (stat & 2) { /* mapping fault */
  207. __spu_trap_data_map(spu, dar, dsisr);
  208. }
  209. if (stat & 4) /* ls compare & suspend on get */
  210. ;
  211. if (stat & 8) /* ls compare & suspend on put */
  212. ;
  213. return stat ? IRQ_HANDLED : IRQ_NONE;
  214. }
  215. EXPORT_SYMBOL_GPL(spu_irq_class_1_bottom);
  216. static irqreturn_t
  217. spu_irq_class_2(int irq, void *data, struct pt_regs *regs)
  218. {
  219. struct spu *spu;
  220. unsigned long stat;
  221. unsigned long mask;
  222. spu = data;
  223. stat = in_be64(&spu->priv1->int_stat_class2_RW);
  224. mask = in_be64(&spu->priv1->int_mask_class2_RW);
  225. pr_debug("class 2 interrupt %d, %lx, %lx\n", irq, stat, mask);
  226. stat &= mask;
  227. if (stat & 1) /* PPC core mailbox */
  228. __spu_trap_mailbox(spu);
  229. if (stat & 2) /* SPU stop-and-signal */
  230. __spu_trap_stop(spu);
  231. if (stat & 4) /* SPU halted */
  232. __spu_trap_halt(spu);
  233. if (stat & 8) /* DMA tag group complete */
  234. __spu_trap_tag_group(spu);
  235. if (stat & 0x10) /* SPU mailbox threshold */
  236. __spu_trap_spubox(spu);
  237. out_be64(&spu->priv1->int_stat_class2_RW, stat);
  238. return stat ? IRQ_HANDLED : IRQ_NONE;
  239. }
  240. static int
  241. spu_request_irqs(struct spu *spu)
  242. {
  243. int ret;
  244. int irq_base;
  245. irq_base = IIC_NODE_STRIDE * spu->node + IIC_SPE_OFFSET;
  246. snprintf(spu->irq_c0, sizeof (spu->irq_c0), "spe%02d.0", spu->number);
  247. ret = request_irq(irq_base + spu->isrc,
  248. spu_irq_class_0, 0, spu->irq_c0, spu);
  249. if (ret)
  250. goto out;
  251. out_be64(&spu->priv1->int_mask_class0_RW, 0x7);
  252. snprintf(spu->irq_c1, sizeof (spu->irq_c1), "spe%02d.1", spu->number);
  253. ret = request_irq(irq_base + IIC_CLASS_STRIDE + spu->isrc,
  254. spu_irq_class_1, 0, spu->irq_c1, spu);
  255. if (ret)
  256. goto out1;
  257. out_be64(&spu->priv1->int_mask_class1_RW, 0x3);
  258. snprintf(spu->irq_c2, sizeof (spu->irq_c2), "spe%02d.2", spu->number);
  259. ret = request_irq(irq_base + 2*IIC_CLASS_STRIDE + spu->isrc,
  260. spu_irq_class_2, 0, spu->irq_c2, spu);
  261. if (ret)
  262. goto out2;
  263. out_be64(&spu->priv1->int_mask_class2_RW, 0xe);
  264. goto out;
  265. out2:
  266. free_irq(irq_base + IIC_CLASS_STRIDE + spu->isrc, spu);
  267. out1:
  268. free_irq(irq_base + spu->isrc, spu);
  269. out:
  270. return ret;
  271. }
  272. static void
  273. spu_free_irqs(struct spu *spu)
  274. {
  275. int irq_base;
  276. irq_base = IIC_NODE_STRIDE * spu->node + IIC_SPE_OFFSET;
  277. free_irq(irq_base + spu->isrc, spu);
  278. free_irq(irq_base + IIC_CLASS_STRIDE + spu->isrc, spu);
  279. free_irq(irq_base + 2*IIC_CLASS_STRIDE + spu->isrc, spu);
  280. }
  281. static LIST_HEAD(spu_list);
  282. static DECLARE_MUTEX(spu_mutex);
  283. static void spu_init_channels(struct spu *spu)
  284. {
  285. static const struct {
  286. unsigned channel;
  287. unsigned count;
  288. } zero_list[] = {
  289. { 0x00, 1, }, { 0x01, 1, }, { 0x03, 1, }, { 0x04, 1, },
  290. { 0x18, 1, }, { 0x19, 1, }, { 0x1b, 1, }, { 0x1d, 1, },
  291. }, count_list[] = {
  292. { 0x00, 0, }, { 0x03, 0, }, { 0x04, 0, }, { 0x15, 16, },
  293. { 0x17, 1, }, { 0x18, 0, }, { 0x19, 0, }, { 0x1b, 0, },
  294. { 0x1c, 1, }, { 0x1d, 0, }, { 0x1e, 1, },
  295. };
  296. struct spu_priv2 *priv2;
  297. int i;
  298. priv2 = spu->priv2;
  299. /* initialize all channel data to zero */
  300. for (i = 0; i < ARRAY_SIZE(zero_list); i++) {
  301. int count;
  302. out_be64(&priv2->spu_chnlcntptr_RW, zero_list[i].channel);
  303. for (count = 0; count < zero_list[i].count; count++)
  304. out_be64(&priv2->spu_chnldata_RW, 0);
  305. }
  306. /* initialize channel counts to meaningful values */
  307. for (i = 0; i < ARRAY_SIZE(count_list); i++) {
  308. out_be64(&priv2->spu_chnlcntptr_RW, count_list[i].channel);
  309. out_be64(&priv2->spu_chnlcnt_RW, count_list[i].count);
  310. }
  311. }
  312. static void spu_init_regs(struct spu *spu)
  313. {
  314. out_be64(&spu->priv1->int_mask_class0_RW, 0x7);
  315. out_be64(&spu->priv1->int_mask_class1_RW, 0x3);
  316. out_be64(&spu->priv1->int_mask_class2_RW, 0xe);
  317. }
  318. struct spu *spu_alloc(void)
  319. {
  320. struct spu *spu;
  321. down(&spu_mutex);
  322. if (!list_empty(&spu_list)) {
  323. spu = list_entry(spu_list.next, struct spu, list);
  324. list_del_init(&spu->list);
  325. pr_debug("Got SPU %x %d\n", spu->isrc, spu->number);
  326. } else {
  327. pr_debug("No SPU left\n");
  328. spu = NULL;
  329. }
  330. up(&spu_mutex);
  331. if (spu) {
  332. spu_init_channels(spu);
  333. spu_init_regs(spu);
  334. }
  335. return spu;
  336. }
  337. EXPORT_SYMBOL_GPL(spu_alloc);
  338. void spu_free(struct spu *spu)
  339. {
  340. down(&spu_mutex);
  341. list_add_tail(&spu->list, &spu_list);
  342. up(&spu_mutex);
  343. }
  344. EXPORT_SYMBOL_GPL(spu_free);
  345. static int spu_handle_mm_fault(struct spu *spu)
  346. {
  347. struct mm_struct *mm = spu->mm;
  348. struct vm_area_struct *vma;
  349. u64 ea, dsisr, is_write;
  350. int ret;
  351. ea = spu->dar;
  352. dsisr = spu->dsisr;
  353. #if 0
  354. if (!IS_VALID_EA(ea)) {
  355. return -EFAULT;
  356. }
  357. #endif /* XXX */
  358. if (mm == NULL) {
  359. return -EFAULT;
  360. }
  361. if (mm->pgd == NULL) {
  362. return -EFAULT;
  363. }
  364. down_read(&mm->mmap_sem);
  365. vma = find_vma(mm, ea);
  366. if (!vma)
  367. goto bad_area;
  368. if (vma->vm_start <= ea)
  369. goto good_area;
  370. if (!(vma->vm_flags & VM_GROWSDOWN))
  371. goto bad_area;
  372. #if 0
  373. if (expand_stack(vma, ea))
  374. goto bad_area;
  375. #endif /* XXX */
  376. good_area:
  377. is_write = dsisr & MFC_DSISR_ACCESS_PUT;
  378. if (is_write) {
  379. if (!(vma->vm_flags & VM_WRITE))
  380. goto bad_area;
  381. } else {
  382. if (dsisr & MFC_DSISR_ACCESS_DENIED)
  383. goto bad_area;
  384. if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
  385. goto bad_area;
  386. }
  387. ret = 0;
  388. switch (handle_mm_fault(mm, vma, ea, is_write)) {
  389. case VM_FAULT_MINOR:
  390. current->min_flt++;
  391. break;
  392. case VM_FAULT_MAJOR:
  393. current->maj_flt++;
  394. break;
  395. case VM_FAULT_SIGBUS:
  396. ret = -EFAULT;
  397. goto bad_area;
  398. case VM_FAULT_OOM:
  399. ret = -ENOMEM;
  400. goto bad_area;
  401. default:
  402. BUG();
  403. }
  404. up_read(&mm->mmap_sem);
  405. return ret;
  406. bad_area:
  407. up_read(&mm->mmap_sem);
  408. return -EFAULT;
  409. }
  410. int spu_irq_class_1_bottom(struct spu *spu)
  411. {
  412. u64 ea, dsisr, access, error = 0UL;
  413. int ret = 0;
  414. ea = spu->dar;
  415. dsisr = spu->dsisr;
  416. if (dsisr & MFC_DSISR_PTE_NOT_FOUND) {
  417. access = (_PAGE_PRESENT | _PAGE_USER);
  418. access |= (dsisr & MFC_DSISR_ACCESS_PUT) ? _PAGE_RW : 0UL;
  419. if (hash_page(ea, access, 0x300) != 0)
  420. error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
  421. }
  422. if ((error & CLASS1_ENABLE_STORAGE_FAULT_INTR) ||
  423. (dsisr & MFC_DSISR_ACCESS_DENIED)) {
  424. if ((ret = spu_handle_mm_fault(spu)) != 0)
  425. error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
  426. else
  427. error &= ~CLASS1_ENABLE_STORAGE_FAULT_INTR;
  428. }
  429. spu->dar = 0UL;
  430. spu->dsisr = 0UL;
  431. if (!error) {
  432. spu_restart_dma(spu);
  433. } else {
  434. __spu_trap_invalid_dma(spu);
  435. }
  436. return ret;
  437. }
  438. static void __iomem * __init map_spe_prop(struct device_node *n,
  439. const char *name)
  440. {
  441. struct address_prop {
  442. unsigned long address;
  443. unsigned int len;
  444. } __attribute__((packed)) *prop;
  445. void *p;
  446. int proplen;
  447. p = get_property(n, name, &proplen);
  448. if (proplen != sizeof (struct address_prop))
  449. return NULL;
  450. prop = p;
  451. return ioremap(prop->address, prop->len);
  452. }
  453. static void spu_unmap(struct spu *spu)
  454. {
  455. iounmap(spu->priv2);
  456. iounmap(spu->priv1);
  457. iounmap(spu->problem);
  458. iounmap((u8 __iomem *)spu->local_store);
  459. }
  460. static int __init spu_map_device(struct spu *spu, struct device_node *spe)
  461. {
  462. char *prop;
  463. int ret;
  464. ret = -ENODEV;
  465. prop = get_property(spe, "isrc", NULL);
  466. if (!prop)
  467. goto out;
  468. spu->isrc = *(unsigned int *)prop;
  469. spu->name = get_property(spe, "name", NULL);
  470. if (!spu->name)
  471. goto out;
  472. prop = get_property(spe, "local-store", NULL);
  473. if (!prop)
  474. goto out;
  475. spu->local_store_phys = *(unsigned long *)prop;
  476. /* we use local store as ram, not io memory */
  477. spu->local_store = (void __force *)map_spe_prop(spe, "local-store");
  478. if (!spu->local_store)
  479. goto out;
  480. spu->problem= map_spe_prop(spe, "problem");
  481. if (!spu->problem)
  482. goto out_unmap;
  483. spu->priv1= map_spe_prop(spe, "priv1");
  484. if (!spu->priv1)
  485. goto out_unmap;
  486. spu->priv2= map_spe_prop(spe, "priv2");
  487. if (!spu->priv2)
  488. goto out_unmap;
  489. ret = 0;
  490. goto out;
  491. out_unmap:
  492. spu_unmap(spu);
  493. out:
  494. return ret;
  495. }
  496. static int __init find_spu_node_id(struct device_node *spe)
  497. {
  498. unsigned int *id;
  499. struct device_node *cpu;
  500. cpu = spe->parent->parent;
  501. id = (unsigned int *)get_property(cpu, "node-id", NULL);
  502. return id ? *id : 0;
  503. }
  504. static int __init create_spu(struct device_node *spe)
  505. {
  506. struct spu *spu;
  507. int ret;
  508. static int number;
  509. ret = -ENOMEM;
  510. spu = kmalloc(sizeof (*spu), GFP_KERNEL);
  511. if (!spu)
  512. goto out;
  513. ret = spu_map_device(spu, spe);
  514. if (ret)
  515. goto out_free;
  516. spu->node = find_spu_node_id(spe);
  517. spu->stop_code = 0;
  518. spu->slb_replace = 0;
  519. spu->mm = NULL;
  520. spu->ctx = NULL;
  521. spu->rq = NULL;
  522. spu->pid = 0;
  523. spu->class_0_pending = 0;
  524. spu->flags = 0UL;
  525. spu->dar = 0UL;
  526. spu->dsisr = 0UL;
  527. spin_lock_init(&spu->register_lock);
  528. out_be64(&spu->priv1->mfc_sdr_RW, mfspr(SPRN_SDR1));
  529. out_be64(&spu->priv1->mfc_sr1_RW, 0x33);
  530. spu->ibox_callback = NULL;
  531. spu->wbox_callback = NULL;
  532. spu->stop_callback = NULL;
  533. down(&spu_mutex);
  534. spu->number = number++;
  535. ret = spu_request_irqs(spu);
  536. if (ret)
  537. goto out_unmap;
  538. list_add(&spu->list, &spu_list);
  539. up(&spu_mutex);
  540. pr_debug(KERN_DEBUG "Using SPE %s %02x %p %p %p %p %d\n",
  541. spu->name, spu->isrc, spu->local_store,
  542. spu->problem, spu->priv1, spu->priv2, spu->number);
  543. goto out;
  544. out_unmap:
  545. up(&spu_mutex);
  546. spu_unmap(spu);
  547. out_free:
  548. kfree(spu);
  549. out:
  550. return ret;
  551. }
  552. static void destroy_spu(struct spu *spu)
  553. {
  554. list_del_init(&spu->list);
  555. spu_free_irqs(spu);
  556. spu_unmap(spu);
  557. kfree(spu);
  558. }
  559. static void cleanup_spu_base(void)
  560. {
  561. struct spu *spu, *tmp;
  562. down(&spu_mutex);
  563. list_for_each_entry_safe(spu, tmp, &spu_list, list)
  564. destroy_spu(spu);
  565. up(&spu_mutex);
  566. }
  567. module_exit(cleanup_spu_base);
  568. static int __init init_spu_base(void)
  569. {
  570. struct device_node *node;
  571. int ret;
  572. ret = -ENODEV;
  573. for (node = of_find_node_by_type(NULL, "spe");
  574. node; node = of_find_node_by_type(node, "spe")) {
  575. ret = create_spu(node);
  576. if (ret) {
  577. printk(KERN_WARNING "%s: Error initializing %s\n",
  578. __FUNCTION__, node->name);
  579. cleanup_spu_base();
  580. break;
  581. }
  582. }
  583. /* in some old firmware versions, the spe is called 'spc', so we
  584. look for that as well */
  585. for (node = of_find_node_by_type(NULL, "spc");
  586. node; node = of_find_node_by_type(node, "spc")) {
  587. ret = create_spu(node);
  588. if (ret) {
  589. printk(KERN_WARNING "%s: Error initializing %s\n",
  590. __FUNCTION__, node->name);
  591. cleanup_spu_base();
  592. break;
  593. }
  594. }
  595. return ret;
  596. }
  597. module_init(init_spu_base);
  598. MODULE_LICENSE("GPL");
  599. MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");