spu_base.c 16 KB

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