spu_base.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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/ptrace.h>
  27. #include <linux/slab.h>
  28. #include <linux/wait.h>
  29. #include <linux/mm.h>
  30. #include <linux/io.h>
  31. #include <linux/mutex.h>
  32. #include <asm/spu.h>
  33. #include <asm/spu_priv1.h>
  34. #include <asm/xmon.h>
  35. const struct spu_management_ops *spu_management_ops;
  36. const struct spu_priv1_ops *spu_priv1_ops;
  37. EXPORT_SYMBOL_GPL(spu_priv1_ops);
  38. static int __spu_trap_invalid_dma(struct spu *spu)
  39. {
  40. pr_debug("%s\n", __FUNCTION__);
  41. spu->dma_callback(spu, SPE_EVENT_INVALID_DMA);
  42. return 0;
  43. }
  44. static int __spu_trap_dma_align(struct spu *spu)
  45. {
  46. pr_debug("%s\n", __FUNCTION__);
  47. spu->dma_callback(spu, SPE_EVENT_DMA_ALIGNMENT);
  48. return 0;
  49. }
  50. static int __spu_trap_error(struct spu *spu)
  51. {
  52. pr_debug("%s\n", __FUNCTION__);
  53. spu->dma_callback(spu, SPE_EVENT_SPE_ERROR);
  54. return 0;
  55. }
  56. static void spu_restart_dma(struct spu *spu)
  57. {
  58. struct spu_priv2 __iomem *priv2 = spu->priv2;
  59. if (!test_bit(SPU_CONTEXT_SWITCH_PENDING, &spu->flags))
  60. out_be64(&priv2->mfc_control_RW, MFC_CNTL_RESTART_DMA_COMMAND);
  61. }
  62. static int __spu_trap_data_seg(struct spu *spu, unsigned long ea)
  63. {
  64. struct spu_priv2 __iomem *priv2 = spu->priv2;
  65. struct mm_struct *mm = spu->mm;
  66. u64 esid, vsid, llp;
  67. pr_debug("%s\n", __FUNCTION__);
  68. if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) {
  69. /* SLBs are pre-loaded for context switch, so
  70. * we should never get here!
  71. */
  72. printk("%s: invalid access during switch!\n", __func__);
  73. return 1;
  74. }
  75. esid = (ea & ESID_MASK) | SLB_ESID_V;
  76. switch(REGION_ID(ea)) {
  77. case USER_REGION_ID:
  78. #ifdef CONFIG_HUGETLB_PAGE
  79. if (in_hugepage_area(mm->context, ea))
  80. llp = mmu_psize_defs[mmu_huge_psize].sllp;
  81. else
  82. #endif
  83. llp = mmu_psize_defs[mmu_virtual_psize].sllp;
  84. vsid = (get_vsid(mm->context.id, ea) << SLB_VSID_SHIFT) |
  85. SLB_VSID_USER | llp;
  86. break;
  87. case VMALLOC_REGION_ID:
  88. llp = mmu_psize_defs[mmu_virtual_psize].sllp;
  89. vsid = (get_kernel_vsid(ea) << SLB_VSID_SHIFT) |
  90. SLB_VSID_KERNEL | llp;
  91. break;
  92. case KERNEL_REGION_ID:
  93. llp = mmu_psize_defs[mmu_linear_psize].sllp;
  94. vsid = (get_kernel_vsid(ea) << SLB_VSID_SHIFT) |
  95. SLB_VSID_KERNEL | llp;
  96. break;
  97. default:
  98. /* Future: support kernel segments so that drivers
  99. * can use SPUs.
  100. */
  101. pr_debug("invalid region access at %016lx\n", ea);
  102. return 1;
  103. }
  104. out_be64(&priv2->slb_index_W, spu->slb_replace);
  105. out_be64(&priv2->slb_vsid_RW, vsid);
  106. out_be64(&priv2->slb_esid_RW, esid);
  107. spu->slb_replace++;
  108. if (spu->slb_replace >= 8)
  109. spu->slb_replace = 0;
  110. spu_restart_dma(spu);
  111. return 0;
  112. }
  113. extern int hash_page(unsigned long ea, unsigned long access, unsigned long trap); //XXX
  114. static int __spu_trap_data_map(struct spu *spu, unsigned long ea, u64 dsisr)
  115. {
  116. pr_debug("%s, %lx, %lx\n", __FUNCTION__, dsisr, ea);
  117. /* Handle kernel space hash faults immediately.
  118. User hash faults need to be deferred to process context. */
  119. if ((dsisr & MFC_DSISR_PTE_NOT_FOUND)
  120. && REGION_ID(ea) != USER_REGION_ID
  121. && hash_page(ea, _PAGE_PRESENT, 0x300) == 0) {
  122. spu_restart_dma(spu);
  123. return 0;
  124. }
  125. if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) {
  126. printk("%s: invalid access during switch!\n", __func__);
  127. return 1;
  128. }
  129. spu->dar = ea;
  130. spu->dsisr = dsisr;
  131. mb();
  132. spu->stop_callback(spu);
  133. return 0;
  134. }
  135. static irqreturn_t
  136. spu_irq_class_0(int irq, void *data)
  137. {
  138. struct spu *spu;
  139. spu = data;
  140. spu->class_0_pending = 1;
  141. spu->stop_callback(spu);
  142. return IRQ_HANDLED;
  143. }
  144. int
  145. spu_irq_class_0_bottom(struct spu *spu)
  146. {
  147. unsigned long stat, mask;
  148. spu->class_0_pending = 0;
  149. mask = spu_int_mask_get(spu, 0);
  150. stat = spu_int_stat_get(spu, 0);
  151. stat &= mask;
  152. if (stat & 1) /* invalid DMA alignment */
  153. __spu_trap_dma_align(spu);
  154. if (stat & 2) /* invalid MFC DMA */
  155. __spu_trap_invalid_dma(spu);
  156. if (stat & 4) /* error on SPU */
  157. __spu_trap_error(spu);
  158. spu_int_stat_clear(spu, 0, stat);
  159. return (stat & 0x7) ? -EIO : 0;
  160. }
  161. EXPORT_SYMBOL_GPL(spu_irq_class_0_bottom);
  162. static irqreturn_t
  163. spu_irq_class_1(int irq, void *data)
  164. {
  165. struct spu *spu;
  166. unsigned long stat, mask, dar, dsisr;
  167. spu = data;
  168. /* atomically read & clear class1 status. */
  169. spin_lock(&spu->register_lock);
  170. mask = spu_int_mask_get(spu, 1);
  171. stat = spu_int_stat_get(spu, 1) & mask;
  172. dar = spu_mfc_dar_get(spu);
  173. dsisr = spu_mfc_dsisr_get(spu);
  174. if (stat & 2) /* mapping fault */
  175. spu_mfc_dsisr_set(spu, 0ul);
  176. spu_int_stat_clear(spu, 1, stat);
  177. spin_unlock(&spu->register_lock);
  178. pr_debug("%s: %lx %lx %lx %lx\n", __FUNCTION__, mask, stat,
  179. dar, dsisr);
  180. if (stat & 1) /* segment fault */
  181. __spu_trap_data_seg(spu, dar);
  182. if (stat & 2) { /* mapping fault */
  183. __spu_trap_data_map(spu, dar, dsisr);
  184. }
  185. if (stat & 4) /* ls compare & suspend on get */
  186. ;
  187. if (stat & 8) /* ls compare & suspend on put */
  188. ;
  189. return stat ? IRQ_HANDLED : IRQ_NONE;
  190. }
  191. EXPORT_SYMBOL_GPL(spu_irq_class_1_bottom);
  192. static irqreturn_t
  193. spu_irq_class_2(int irq, void *data)
  194. {
  195. struct spu *spu;
  196. unsigned long stat;
  197. unsigned long mask;
  198. spu = data;
  199. spin_lock(&spu->register_lock);
  200. stat = spu_int_stat_get(spu, 2);
  201. mask = spu_int_mask_get(spu, 2);
  202. /* ignore interrupts we're not waiting for */
  203. stat &= mask;
  204. /*
  205. * mailbox interrupts (0x1 and 0x10) are level triggered.
  206. * mask them now before acknowledging.
  207. */
  208. if (stat & 0x11)
  209. spu_int_mask_and(spu, 2, ~(stat & 0x11));
  210. /* acknowledge all interrupts before the callbacks */
  211. spu_int_stat_clear(spu, 2, stat);
  212. spin_unlock(&spu->register_lock);
  213. pr_debug("class 2 interrupt %d, %lx, %lx\n", irq, stat, mask);
  214. if (stat & 1) /* PPC core mailbox */
  215. spu->ibox_callback(spu);
  216. if (stat & 2) /* SPU stop-and-signal */
  217. spu->stop_callback(spu);
  218. if (stat & 4) /* SPU halted */
  219. spu->stop_callback(spu);
  220. if (stat & 8) /* DMA tag group complete */
  221. spu->mfc_callback(spu);
  222. if (stat & 0x10) /* SPU mailbox threshold */
  223. spu->wbox_callback(spu);
  224. return stat ? IRQ_HANDLED : IRQ_NONE;
  225. }
  226. static int spu_request_irqs(struct spu *spu)
  227. {
  228. int ret = 0;
  229. if (spu->irqs[0] != NO_IRQ) {
  230. snprintf(spu->irq_c0, sizeof (spu->irq_c0), "spe%02d.0",
  231. spu->number);
  232. ret = request_irq(spu->irqs[0], spu_irq_class_0,
  233. IRQF_DISABLED,
  234. spu->irq_c0, spu);
  235. if (ret)
  236. goto bail0;
  237. }
  238. if (spu->irqs[1] != NO_IRQ) {
  239. snprintf(spu->irq_c1, sizeof (spu->irq_c1), "spe%02d.1",
  240. spu->number);
  241. ret = request_irq(spu->irqs[1], spu_irq_class_1,
  242. IRQF_DISABLED,
  243. spu->irq_c1, spu);
  244. if (ret)
  245. goto bail1;
  246. }
  247. if (spu->irqs[2] != NO_IRQ) {
  248. snprintf(spu->irq_c2, sizeof (spu->irq_c2), "spe%02d.2",
  249. spu->number);
  250. ret = request_irq(spu->irqs[2], spu_irq_class_2,
  251. IRQF_DISABLED,
  252. spu->irq_c2, spu);
  253. if (ret)
  254. goto bail2;
  255. }
  256. return 0;
  257. bail2:
  258. if (spu->irqs[1] != NO_IRQ)
  259. free_irq(spu->irqs[1], spu);
  260. bail1:
  261. if (spu->irqs[0] != NO_IRQ)
  262. free_irq(spu->irqs[0], spu);
  263. bail0:
  264. return ret;
  265. }
  266. static void spu_free_irqs(struct spu *spu)
  267. {
  268. if (spu->irqs[0] != NO_IRQ)
  269. free_irq(spu->irqs[0], spu);
  270. if (spu->irqs[1] != NO_IRQ)
  271. free_irq(spu->irqs[1], spu);
  272. if (spu->irqs[2] != NO_IRQ)
  273. free_irq(spu->irqs[2], spu);
  274. }
  275. static struct list_head spu_list[MAX_NUMNODES];
  276. static LIST_HEAD(spu_full_list);
  277. static DEFINE_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 __iomem *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. struct spu *spu_alloc_node(int node)
  308. {
  309. struct spu *spu = NULL;
  310. mutex_lock(&spu_mutex);
  311. if (!list_empty(&spu_list[node])) {
  312. spu = list_entry(spu_list[node].next, struct spu, list);
  313. list_del_init(&spu->list);
  314. pr_debug("Got SPU %d %d\n", spu->number, spu->node);
  315. spu_init_channels(spu);
  316. }
  317. mutex_unlock(&spu_mutex);
  318. return spu;
  319. }
  320. EXPORT_SYMBOL_GPL(spu_alloc_node);
  321. struct spu *spu_alloc(void)
  322. {
  323. struct spu *spu = NULL;
  324. int node;
  325. for (node = 0; node < MAX_NUMNODES; node++) {
  326. spu = spu_alloc_node(node);
  327. if (spu)
  328. break;
  329. }
  330. return spu;
  331. }
  332. void spu_free(struct spu *spu)
  333. {
  334. mutex_lock(&spu_mutex);
  335. list_add_tail(&spu->list, &spu_list[spu->node]);
  336. mutex_unlock(&spu_mutex);
  337. }
  338. EXPORT_SYMBOL_GPL(spu_free);
  339. static int spu_handle_mm_fault(struct spu *spu)
  340. {
  341. struct mm_struct *mm = spu->mm;
  342. struct vm_area_struct *vma;
  343. u64 ea, dsisr, is_write;
  344. int ret;
  345. ea = spu->dar;
  346. dsisr = spu->dsisr;
  347. #if 0
  348. if (!IS_VALID_EA(ea)) {
  349. return -EFAULT;
  350. }
  351. #endif /* XXX */
  352. if (mm == NULL) {
  353. return -EFAULT;
  354. }
  355. if (mm->pgd == NULL) {
  356. return -EFAULT;
  357. }
  358. down_read(&mm->mmap_sem);
  359. vma = find_vma(mm, ea);
  360. if (!vma)
  361. goto bad_area;
  362. if (vma->vm_start <= ea)
  363. goto good_area;
  364. if (!(vma->vm_flags & VM_GROWSDOWN))
  365. goto bad_area;
  366. #if 0
  367. if (expand_stack(vma, ea))
  368. goto bad_area;
  369. #endif /* XXX */
  370. good_area:
  371. is_write = dsisr & MFC_DSISR_ACCESS_PUT;
  372. if (is_write) {
  373. if (!(vma->vm_flags & VM_WRITE))
  374. goto bad_area;
  375. } else {
  376. if (dsisr & MFC_DSISR_ACCESS_DENIED)
  377. goto bad_area;
  378. if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
  379. goto bad_area;
  380. }
  381. ret = 0;
  382. switch (handle_mm_fault(mm, vma, ea, is_write)) {
  383. case VM_FAULT_MINOR:
  384. current->min_flt++;
  385. break;
  386. case VM_FAULT_MAJOR:
  387. current->maj_flt++;
  388. break;
  389. case VM_FAULT_SIGBUS:
  390. ret = -EFAULT;
  391. goto bad_area;
  392. case VM_FAULT_OOM:
  393. ret = -ENOMEM;
  394. goto bad_area;
  395. default:
  396. BUG();
  397. }
  398. up_read(&mm->mmap_sem);
  399. return ret;
  400. bad_area:
  401. up_read(&mm->mmap_sem);
  402. return -EFAULT;
  403. }
  404. int spu_irq_class_1_bottom(struct spu *spu)
  405. {
  406. u64 ea, dsisr, access, error = 0UL;
  407. int ret = 0;
  408. ea = spu->dar;
  409. dsisr = spu->dsisr;
  410. if (dsisr & (MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED)) {
  411. u64 flags;
  412. access = (_PAGE_PRESENT | _PAGE_USER);
  413. access |= (dsisr & MFC_DSISR_ACCESS_PUT) ? _PAGE_RW : 0UL;
  414. local_irq_save(flags);
  415. if (hash_page(ea, access, 0x300) != 0)
  416. error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
  417. local_irq_restore(flags);
  418. }
  419. if (error & CLASS1_ENABLE_STORAGE_FAULT_INTR) {
  420. if ((ret = spu_handle_mm_fault(spu)) != 0)
  421. error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
  422. else
  423. error &= ~CLASS1_ENABLE_STORAGE_FAULT_INTR;
  424. }
  425. spu->dar = 0UL;
  426. spu->dsisr = 0UL;
  427. if (!error) {
  428. spu_restart_dma(spu);
  429. } else {
  430. spu->dma_callback(spu, SPE_EVENT_SPE_DATA_STORAGE);
  431. }
  432. return ret;
  433. }
  434. struct sysdev_class spu_sysdev_class = {
  435. set_kset_name("spu")
  436. };
  437. int spu_add_sysdev_attr(struct sysdev_attribute *attr)
  438. {
  439. struct spu *spu;
  440. mutex_lock(&spu_mutex);
  441. list_for_each_entry(spu, &spu_full_list, full_list)
  442. sysdev_create_file(&spu->sysdev, attr);
  443. mutex_unlock(&spu_mutex);
  444. return 0;
  445. }
  446. EXPORT_SYMBOL_GPL(spu_add_sysdev_attr);
  447. int spu_add_sysdev_attr_group(struct attribute_group *attrs)
  448. {
  449. struct spu *spu;
  450. mutex_lock(&spu_mutex);
  451. list_for_each_entry(spu, &spu_full_list, full_list)
  452. sysfs_create_group(&spu->sysdev.kobj, attrs);
  453. mutex_unlock(&spu_mutex);
  454. return 0;
  455. }
  456. EXPORT_SYMBOL_GPL(spu_add_sysdev_attr_group);
  457. void spu_remove_sysdev_attr(struct sysdev_attribute *attr)
  458. {
  459. struct spu *spu;
  460. mutex_lock(&spu_mutex);
  461. list_for_each_entry(spu, &spu_full_list, full_list)
  462. sysdev_remove_file(&spu->sysdev, attr);
  463. mutex_unlock(&spu_mutex);
  464. }
  465. EXPORT_SYMBOL_GPL(spu_remove_sysdev_attr);
  466. void spu_remove_sysdev_attr_group(struct attribute_group *attrs)
  467. {
  468. struct spu *spu;
  469. mutex_lock(&spu_mutex);
  470. list_for_each_entry(spu, &spu_full_list, full_list)
  471. sysfs_remove_group(&spu->sysdev.kobj, attrs);
  472. mutex_unlock(&spu_mutex);
  473. }
  474. EXPORT_SYMBOL_GPL(spu_remove_sysdev_attr_group);
  475. static int spu_create_sysdev(struct spu *spu)
  476. {
  477. int ret;
  478. spu->sysdev.id = spu->number;
  479. spu->sysdev.cls = &spu_sysdev_class;
  480. ret = sysdev_register(&spu->sysdev);
  481. if (ret) {
  482. printk(KERN_ERR "Can't register SPU %d with sysfs\n",
  483. spu->number);
  484. return ret;
  485. }
  486. sysfs_add_device_to_node(&spu->sysdev, spu->node);
  487. return 0;
  488. }
  489. static void spu_destroy_sysdev(struct spu *spu)
  490. {
  491. sysfs_remove_device_from_node(&spu->sysdev, spu->node);
  492. sysdev_unregister(&spu->sysdev);
  493. }
  494. static int __init create_spu(void *data)
  495. {
  496. struct spu *spu;
  497. int ret;
  498. static int number;
  499. ret = -ENOMEM;
  500. spu = kzalloc(sizeof (*spu), GFP_KERNEL);
  501. if (!spu)
  502. goto out;
  503. spin_lock_init(&spu->register_lock);
  504. mutex_lock(&spu_mutex);
  505. spu->number = number++;
  506. mutex_unlock(&spu_mutex);
  507. ret = spu_create_spu(spu, data);
  508. if (ret)
  509. goto out_free;
  510. spu_mfc_sdr_setup(spu);
  511. spu_mfc_sr1_set(spu, 0x33);
  512. ret = spu_request_irqs(spu);
  513. if (ret)
  514. goto out_destroy;
  515. ret = spu_create_sysdev(spu);
  516. if (ret)
  517. goto out_free_irqs;
  518. mutex_lock(&spu_mutex);
  519. list_add(&spu->list, &spu_list[spu->node]);
  520. list_add(&spu->full_list, &spu_full_list);
  521. mutex_unlock(&spu_mutex);
  522. goto out;
  523. out_free_irqs:
  524. spu_free_irqs(spu);
  525. out_destroy:
  526. spu_destroy_spu(spu);
  527. out_free:
  528. kfree(spu);
  529. out:
  530. return ret;
  531. }
  532. static void destroy_spu(struct spu *spu)
  533. {
  534. list_del_init(&spu->list);
  535. list_del_init(&spu->full_list);
  536. spu_destroy_sysdev(spu);
  537. spu_free_irqs(spu);
  538. spu_destroy_spu(spu);
  539. kfree(spu);
  540. }
  541. static void cleanup_spu_base(void)
  542. {
  543. struct spu *spu, *tmp;
  544. int node;
  545. mutex_lock(&spu_mutex);
  546. for (node = 0; node < MAX_NUMNODES; node++) {
  547. list_for_each_entry_safe(spu, tmp, &spu_list[node], list)
  548. destroy_spu(spu);
  549. }
  550. mutex_unlock(&spu_mutex);
  551. sysdev_class_unregister(&spu_sysdev_class);
  552. }
  553. module_exit(cleanup_spu_base);
  554. static int __init init_spu_base(void)
  555. {
  556. int i, ret;
  557. if (!spu_management_ops)
  558. return 0;
  559. /* create sysdev class for spus */
  560. ret = sysdev_class_register(&spu_sysdev_class);
  561. if (ret)
  562. return ret;
  563. for (i = 0; i < MAX_NUMNODES; i++)
  564. INIT_LIST_HEAD(&spu_list[i]);
  565. ret = spu_enumerate_spus(create_spu);
  566. if (ret) {
  567. printk(KERN_WARNING "%s: Error initializing spus\n",
  568. __FUNCTION__);
  569. cleanup_spu_base();
  570. return ret;
  571. }
  572. xmon_register_spus(&spu_full_list);
  573. return ret;
  574. }
  575. module_init(init_spu_base);
  576. MODULE_LICENSE("GPL");
  577. MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");