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 <linux/mutex.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, %lx, %lx\n", __FUNCTION__, dsisr, ea);
  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. spu_int_mask_and(spu, 2, ~0x1);
  123. spin_unlock(&spu->register_lock);
  124. return 0;
  125. }
  126. static int __spu_trap_stop(struct spu *spu)
  127. {
  128. pr_debug("%s\n", __FUNCTION__);
  129. spu->stop_code = in_be32(&spu->problem->spu_status_R);
  130. if (spu->stop_callback)
  131. spu->stop_callback(spu);
  132. return 0;
  133. }
  134. static int __spu_trap_halt(struct spu *spu)
  135. {
  136. pr_debug("%s\n", __FUNCTION__);
  137. spu->stop_code = in_be32(&spu->problem->spu_status_R);
  138. if (spu->stop_callback)
  139. spu->stop_callback(spu);
  140. return 0;
  141. }
  142. static int __spu_trap_tag_group(struct spu *spu)
  143. {
  144. pr_debug("%s\n", __FUNCTION__);
  145. spu->mfc_callback(spu);
  146. return 0;
  147. }
  148. static int __spu_trap_spubox(struct spu *spu)
  149. {
  150. if (spu->wbox_callback)
  151. spu->wbox_callback(spu);
  152. /* atomically disable SPU mailbox interrupts */
  153. spin_lock(&spu->register_lock);
  154. spu_int_mask_and(spu, 2, ~0x10);
  155. spin_unlock(&spu->register_lock);
  156. return 0;
  157. }
  158. static irqreturn_t
  159. spu_irq_class_0(int irq, void *data, struct pt_regs *regs)
  160. {
  161. struct spu *spu;
  162. spu = data;
  163. spu->class_0_pending = 1;
  164. if (spu->stop_callback)
  165. spu->stop_callback(spu);
  166. return IRQ_HANDLED;
  167. }
  168. int
  169. spu_irq_class_0_bottom(struct spu *spu)
  170. {
  171. unsigned long stat, mask;
  172. spu->class_0_pending = 0;
  173. mask = spu_int_mask_get(spu, 0);
  174. stat = spu_int_stat_get(spu, 0);
  175. stat &= mask;
  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. spu_int_stat_clear(spu, 0, 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 = spu_int_mask_get(spu, 1);
  195. stat = spu_int_stat_get(spu, 1) & mask;
  196. dar = spu_mfc_dar_get(spu);
  197. dsisr = spu_mfc_dsisr_get(spu);
  198. if (stat & 2) /* mapping fault */
  199. spu_mfc_dsisr_set(spu, 0ul);
  200. spu_int_stat_clear(spu, 1, stat);
  201. spin_unlock(&spu->register_lock);
  202. pr_debug("%s: %lx %lx %lx %lx\n", __FUNCTION__, mask, stat,
  203. dar, dsisr);
  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 = spu_int_stat_get(spu, 2);
  224. mask = spu_int_mask_get(spu, 2);
  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. spu_int_stat_clear(spu, 2, 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. 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. snprintf(spu->irq_c2, sizeof (spu->irq_c2), "spe%02d.2", spu->number);
  257. ret = request_irq(irq_base + 2*IIC_CLASS_STRIDE + spu->isrc,
  258. spu_irq_class_2, 0, spu->irq_c2, spu);
  259. if (ret)
  260. goto out2;
  261. goto out;
  262. out2:
  263. free_irq(irq_base + IIC_CLASS_STRIDE + spu->isrc, spu);
  264. out1:
  265. free_irq(irq_base + spu->isrc, spu);
  266. out:
  267. return ret;
  268. }
  269. static void
  270. spu_free_irqs(struct spu *spu)
  271. {
  272. int irq_base;
  273. irq_base = IIC_NODE_STRIDE * spu->node + IIC_SPE_OFFSET;
  274. free_irq(irq_base + spu->isrc, spu);
  275. free_irq(irq_base + IIC_CLASS_STRIDE + spu->isrc, spu);
  276. free_irq(irq_base + 2*IIC_CLASS_STRIDE + spu->isrc, spu);
  277. }
  278. static LIST_HEAD(spu_list);
  279. static DEFINE_MUTEX(spu_mutex);
  280. static void spu_init_channels(struct spu *spu)
  281. {
  282. static const struct {
  283. unsigned channel;
  284. unsigned count;
  285. } zero_list[] = {
  286. { 0x00, 1, }, { 0x01, 1, }, { 0x03, 1, }, { 0x04, 1, },
  287. { 0x18, 1, }, { 0x19, 1, }, { 0x1b, 1, }, { 0x1d, 1, },
  288. }, count_list[] = {
  289. { 0x00, 0, }, { 0x03, 0, }, { 0x04, 0, }, { 0x15, 16, },
  290. { 0x17, 1, }, { 0x18, 0, }, { 0x19, 0, }, { 0x1b, 0, },
  291. { 0x1c, 1, }, { 0x1d, 0, }, { 0x1e, 1, },
  292. };
  293. struct spu_priv2 __iomem *priv2;
  294. int i;
  295. priv2 = spu->priv2;
  296. /* initialize all channel data to zero */
  297. for (i = 0; i < ARRAY_SIZE(zero_list); i++) {
  298. int count;
  299. out_be64(&priv2->spu_chnlcntptr_RW, zero_list[i].channel);
  300. for (count = 0; count < zero_list[i].count; count++)
  301. out_be64(&priv2->spu_chnldata_RW, 0);
  302. }
  303. /* initialize channel counts to meaningful values */
  304. for (i = 0; i < ARRAY_SIZE(count_list); i++) {
  305. out_be64(&priv2->spu_chnlcntptr_RW, count_list[i].channel);
  306. out_be64(&priv2->spu_chnlcnt_RW, count_list[i].count);
  307. }
  308. }
  309. struct spu *spu_alloc(void)
  310. {
  311. struct spu *spu;
  312. mutex_lock(&spu_mutex);
  313. if (!list_empty(&spu_list)) {
  314. spu = list_entry(spu_list.next, struct spu, list);
  315. list_del_init(&spu->list);
  316. pr_debug("Got SPU %x %d\n", spu->isrc, spu->number);
  317. } else {
  318. pr_debug("No SPU left\n");
  319. spu = NULL;
  320. }
  321. mutex_unlock(&spu_mutex);
  322. if (spu)
  323. spu_init_channels(spu);
  324. return spu;
  325. }
  326. EXPORT_SYMBOL_GPL(spu_alloc);
  327. void spu_free(struct spu *spu)
  328. {
  329. mutex_lock(&spu_mutex);
  330. list_add_tail(&spu->list, &spu_list);
  331. mutex_unlock(&spu_mutex);
  332. }
  333. EXPORT_SYMBOL_GPL(spu_free);
  334. static int spu_handle_mm_fault(struct spu *spu)
  335. {
  336. struct mm_struct *mm = spu->mm;
  337. struct vm_area_struct *vma;
  338. u64 ea, dsisr, is_write;
  339. int ret;
  340. ea = spu->dar;
  341. dsisr = spu->dsisr;
  342. #if 0
  343. if (!IS_VALID_EA(ea)) {
  344. return -EFAULT;
  345. }
  346. #endif /* XXX */
  347. if (mm == NULL) {
  348. return -EFAULT;
  349. }
  350. if (mm->pgd == NULL) {
  351. return -EFAULT;
  352. }
  353. down_read(&mm->mmap_sem);
  354. vma = find_vma(mm, ea);
  355. if (!vma)
  356. goto bad_area;
  357. if (vma->vm_start <= ea)
  358. goto good_area;
  359. if (!(vma->vm_flags & VM_GROWSDOWN))
  360. goto bad_area;
  361. #if 0
  362. if (expand_stack(vma, ea))
  363. goto bad_area;
  364. #endif /* XXX */
  365. good_area:
  366. is_write = dsisr & MFC_DSISR_ACCESS_PUT;
  367. if (is_write) {
  368. if (!(vma->vm_flags & VM_WRITE))
  369. goto bad_area;
  370. } else {
  371. if (dsisr & MFC_DSISR_ACCESS_DENIED)
  372. goto bad_area;
  373. if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
  374. goto bad_area;
  375. }
  376. ret = 0;
  377. switch (handle_mm_fault(mm, vma, ea, is_write)) {
  378. case VM_FAULT_MINOR:
  379. current->min_flt++;
  380. break;
  381. case VM_FAULT_MAJOR:
  382. current->maj_flt++;
  383. break;
  384. case VM_FAULT_SIGBUS:
  385. ret = -EFAULT;
  386. goto bad_area;
  387. case VM_FAULT_OOM:
  388. ret = -ENOMEM;
  389. goto bad_area;
  390. default:
  391. BUG();
  392. }
  393. up_read(&mm->mmap_sem);
  394. return ret;
  395. bad_area:
  396. up_read(&mm->mmap_sem);
  397. return -EFAULT;
  398. }
  399. int spu_irq_class_1_bottom(struct spu *spu)
  400. {
  401. u64 ea, dsisr, access, error = 0UL;
  402. int ret = 0;
  403. ea = spu->dar;
  404. dsisr = spu->dsisr;
  405. if (dsisr & (MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED)) {
  406. access = (_PAGE_PRESENT | _PAGE_USER);
  407. access |= (dsisr & MFC_DSISR_ACCESS_PUT) ? _PAGE_RW : 0UL;
  408. if (hash_page(ea, access, 0x300) != 0)
  409. error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
  410. }
  411. if (error & CLASS1_ENABLE_STORAGE_FAULT_INTR) {
  412. if ((ret = spu_handle_mm_fault(spu)) != 0)
  413. error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
  414. else
  415. error &= ~CLASS1_ENABLE_STORAGE_FAULT_INTR;
  416. }
  417. spu->dar = 0UL;
  418. spu->dsisr = 0UL;
  419. if (!error) {
  420. spu_restart_dma(spu);
  421. } else {
  422. __spu_trap_invalid_dma(spu);
  423. }
  424. return ret;
  425. }
  426. void spu_irq_setaffinity(struct spu *spu, int cpu)
  427. {
  428. u64 target = iic_get_target_id(cpu);
  429. u64 route = target << 48 | target << 32 | target << 16;
  430. spu_int_route_set(spu, route);
  431. }
  432. EXPORT_SYMBOL_GPL(spu_irq_setaffinity);
  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. prop = get_property(spe, "problem", NULL);
  476. if (!prop)
  477. goto out_unmap;
  478. spu->problem_phys = *(unsigned long *)prop;
  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. /* priv1 is not available on a hypervisor */
  484. spu->priv2= map_spe_prop(spe, "priv2");
  485. if (!spu->priv2)
  486. goto out_unmap;
  487. ret = 0;
  488. goto out;
  489. out_unmap:
  490. spu_unmap(spu);
  491. out:
  492. return ret;
  493. }
  494. static int __init find_spu_node_id(struct device_node *spe)
  495. {
  496. unsigned int *id;
  497. struct device_node *cpu;
  498. cpu = spe->parent->parent;
  499. id = (unsigned int *)get_property(cpu, "node-id", NULL);
  500. return id ? *id : 0;
  501. }
  502. static int __init create_spu(struct device_node *spe)
  503. {
  504. struct spu *spu;
  505. int ret;
  506. static int number;
  507. ret = -ENOMEM;
  508. spu = kmalloc(sizeof (*spu), GFP_KERNEL);
  509. if (!spu)
  510. goto out;
  511. ret = spu_map_device(spu, spe);
  512. if (ret)
  513. goto out_free;
  514. spu->node = find_spu_node_id(spe);
  515. spu->stop_code = 0;
  516. spu->slb_replace = 0;
  517. spu->mm = NULL;
  518. spu->ctx = NULL;
  519. spu->rq = NULL;
  520. spu->pid = 0;
  521. spu->class_0_pending = 0;
  522. spu->flags = 0UL;
  523. spu->dar = 0UL;
  524. spu->dsisr = 0UL;
  525. spin_lock_init(&spu->register_lock);
  526. spu_mfc_sdr_set(spu, mfspr(SPRN_SDR1));
  527. spu_mfc_sr1_set(spu, 0x33);
  528. spu->ibox_callback = NULL;
  529. spu->wbox_callback = NULL;
  530. spu->stop_callback = NULL;
  531. spu->mfc_callback = NULL;
  532. mutex_lock(&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. mutex_unlock(&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. mutex_unlock(&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. mutex_lock(&spu_mutex);
  562. list_for_each_entry_safe(spu, tmp, &spu_list, list)
  563. destroy_spu(spu);
  564. mutex_unlock(&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>");