Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 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 | |
Arnd Bergmann | 3b3d22c | 2005-12-05 22:52:24 -0500 | [diff] [blame] | 23 | #undef DEBUG |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 24 | |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/module.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 28 | #include <linux/ptrace.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/wait.h> |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 31 | #include <linux/mm.h> |
| 32 | #include <linux/io.h> |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 33 | #include <linux/mutex.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 34 | #include <asm/spu.h> |
Geoff Levand | 540270d | 2006-06-19 20:33:29 +0200 | [diff] [blame] | 35 | #include <asm/spu_priv1.h> |
Michael Ellerman | ff8a8f2 | 2006-10-24 18:31:27 +0200 | [diff] [blame] | 36 | #include <asm/xmon.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 37 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 38 | const struct spu_management_ops *spu_management_ops; |
Geoff Levand | 540270d | 2006-06-19 20:33:29 +0200 | [diff] [blame] | 39 | const struct spu_priv1_ops *spu_priv1_ops; |
| 40 | |
| 41 | EXPORT_SYMBOL_GPL(spu_priv1_ops); |
| 42 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 43 | static int __spu_trap_invalid_dma(struct spu *spu) |
| 44 | { |
| 45 | pr_debug("%s\n", __FUNCTION__); |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 46 | spu->dma_callback(spu, SPE_EVENT_INVALID_DMA); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static int __spu_trap_dma_align(struct spu *spu) |
| 51 | { |
| 52 | pr_debug("%s\n", __FUNCTION__); |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 53 | spu->dma_callback(spu, SPE_EVENT_DMA_ALIGNMENT); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static int __spu_trap_error(struct spu *spu) |
| 58 | { |
| 59 | pr_debug("%s\n", __FUNCTION__); |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 60 | spu->dma_callback(spu, SPE_EVENT_SPE_ERROR); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static void spu_restart_dma(struct spu *spu) |
| 65 | { |
| 66 | struct spu_priv2 __iomem *priv2 = spu->priv2; |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 67 | |
Arnd Bergmann | 8837d92 | 2006-01-04 20:31:28 +0100 | [diff] [blame] | 68 | if (!test_bit(SPU_CONTEXT_SWITCH_PENDING, &spu->flags)) |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 69 | out_be64(&priv2->mfc_control_RW, MFC_CNTL_RESTART_DMA_COMMAND); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static int __spu_trap_data_seg(struct spu *spu, unsigned long ea) |
| 73 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 74 | struct spu_priv2 __iomem *priv2 = spu->priv2; |
| 75 | struct mm_struct *mm = spu->mm; |
arnd@arndb.de | 724bd80 | 2006-06-19 20:33:23 +0200 | [diff] [blame] | 76 | u64 esid, vsid, llp; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 77 | |
| 78 | pr_debug("%s\n", __FUNCTION__); |
| 79 | |
Arnd Bergmann | 8837d92 | 2006-01-04 20:31:28 +0100 | [diff] [blame] | 80 | if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 81 | /* SLBs are pre-loaded for context switch, so |
| 82 | * we should never get here! |
| 83 | */ |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 84 | printk("%s: invalid access during switch!\n", __func__); |
| 85 | return 1; |
| 86 | } |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 87 | esid = (ea & ESID_MASK) | SLB_ESID_V; |
| 88 | |
| 89 | switch(REGION_ID(ea)) { |
| 90 | case USER_REGION_ID: |
| 91 | #ifdef CONFIG_HUGETLB_PAGE |
| 92 | if (in_hugepage_area(mm->context, ea)) |
| 93 | llp = mmu_psize_defs[mmu_huge_psize].sllp; |
| 94 | else |
| 95 | #endif |
| 96 | llp = mmu_psize_defs[mmu_virtual_psize].sllp; |
| 97 | vsid = (get_vsid(mm->context.id, ea) << SLB_VSID_SHIFT) | |
| 98 | SLB_VSID_USER | llp; |
| 99 | break; |
| 100 | case VMALLOC_REGION_ID: |
| 101 | llp = mmu_psize_defs[mmu_virtual_psize].sllp; |
| 102 | vsid = (get_kernel_vsid(ea) << SLB_VSID_SHIFT) | |
| 103 | SLB_VSID_KERNEL | llp; |
| 104 | break; |
| 105 | case KERNEL_REGION_ID: |
| 106 | llp = mmu_psize_defs[mmu_linear_psize].sllp; |
| 107 | vsid = (get_kernel_vsid(ea) << SLB_VSID_SHIFT) | |
| 108 | SLB_VSID_KERNEL | llp; |
| 109 | break; |
| 110 | default: |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 111 | /* Future: support kernel segments so that drivers |
| 112 | * can use SPUs. |
| 113 | */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 114 | pr_debug("invalid region access at %016lx\n", ea); |
| 115 | return 1; |
| 116 | } |
| 117 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 118 | out_be64(&priv2->slb_index_W, spu->slb_replace); |
| 119 | out_be64(&priv2->slb_vsid_RW, vsid); |
| 120 | out_be64(&priv2->slb_esid_RW, esid); |
| 121 | |
| 122 | spu->slb_replace++; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 123 | if (spu->slb_replace >= 8) |
| 124 | spu->slb_replace = 0; |
| 125 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 126 | spu_restart_dma(spu); |
| 127 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 128 | return 0; |
| 129 | } |
| 130 | |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 131 | extern int hash_page(unsigned long ea, unsigned long access, unsigned long trap); //XXX |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 132 | static int __spu_trap_data_map(struct spu *spu, unsigned long ea, u64 dsisr) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 133 | { |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 134 | pr_debug("%s, %lx, %lx\n", __FUNCTION__, dsisr, ea); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 135 | |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 136 | /* Handle kernel space hash faults immediately. |
| 137 | User hash faults need to be deferred to process context. */ |
| 138 | if ((dsisr & MFC_DSISR_PTE_NOT_FOUND) |
| 139 | && REGION_ID(ea) != USER_REGION_ID |
| 140 | && hash_page(ea, _PAGE_PRESENT, 0x300) == 0) { |
| 141 | spu_restart_dma(spu); |
| 142 | return 0; |
| 143 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 144 | |
Arnd Bergmann | 8837d92 | 2006-01-04 20:31:28 +0100 | [diff] [blame] | 145 | if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) { |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 146 | printk("%s: invalid access during switch!\n", __func__); |
| 147 | return 1; |
| 148 | } |
| 149 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 150 | spu->dar = ea; |
| 151 | spu->dsisr = dsisr; |
| 152 | mb(); |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 153 | spu->stop_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | static irqreturn_t |
Olaf Hering | f5a9245 | 2006-10-06 22:52:16 +0200 | [diff] [blame] | 158 | spu_irq_class_0(int irq, void *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 159 | { |
| 160 | struct spu *spu; |
| 161 | |
| 162 | spu = data; |
| 163 | spu->class_0_pending = 1; |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 164 | spu->stop_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 165 | |
| 166 | return IRQ_HANDLED; |
| 167 | } |
| 168 | |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 169 | int |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 170 | spu_irq_class_0_bottom(struct spu *spu) |
| 171 | { |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 172 | unsigned long stat, mask; |
Ishizaki Kou | 3650cfe | 2007-01-12 09:52:41 +0900 | [diff] [blame] | 173 | unsigned long flags; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 174 | |
| 175 | spu->class_0_pending = 0; |
| 176 | |
Ishizaki Kou | 3650cfe | 2007-01-12 09:52:41 +0900 | [diff] [blame] | 177 | spin_lock_irqsave(&spu->register_lock, flags); |
Arnd Bergmann | f0831ac | 2006-01-04 20:31:30 +0100 | [diff] [blame] | 178 | mask = spu_int_mask_get(spu, 0); |
| 179 | stat = spu_int_stat_get(spu, 0); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 180 | |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 181 | stat &= mask; |
| 182 | |
Arnd Bergmann | 2cd90bc | 2006-06-23 20:57:50 +0200 | [diff] [blame] | 183 | if (stat & 1) /* invalid DMA alignment */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 184 | __spu_trap_dma_align(spu); |
| 185 | |
Arnd Bergmann | 2cd90bc | 2006-06-23 20:57:50 +0200 | [diff] [blame] | 186 | if (stat & 2) /* invalid MFC DMA */ |
| 187 | __spu_trap_invalid_dma(spu); |
| 188 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 189 | if (stat & 4) /* error on SPU */ |
| 190 | __spu_trap_error(spu); |
| 191 | |
Arnd Bergmann | f0831ac | 2006-01-04 20:31:30 +0100 | [diff] [blame] | 192 | spu_int_stat_clear(spu, 0, stat); |
Ishizaki Kou | 3650cfe | 2007-01-12 09:52:41 +0900 | [diff] [blame] | 193 | spin_unlock_irqrestore(&spu->register_lock, flags); |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 194 | |
| 195 | return (stat & 0x7) ? -EIO : 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 196 | } |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 197 | EXPORT_SYMBOL_GPL(spu_irq_class_0_bottom); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 198 | |
| 199 | static irqreturn_t |
Olaf Hering | f5a9245 | 2006-10-06 22:52:16 +0200 | [diff] [blame] | 200 | spu_irq_class_1(int irq, void *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 201 | { |
| 202 | struct spu *spu; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 203 | unsigned long stat, mask, dar, dsisr; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 204 | |
| 205 | spu = data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 206 | |
| 207 | /* atomically read & clear class1 status. */ |
| 208 | spin_lock(&spu->register_lock); |
Arnd Bergmann | f0831ac | 2006-01-04 20:31:30 +0100 | [diff] [blame] | 209 | mask = spu_int_mask_get(spu, 1); |
| 210 | stat = spu_int_stat_get(spu, 1) & mask; |
| 211 | dar = spu_mfc_dar_get(spu); |
| 212 | dsisr = spu_mfc_dsisr_get(spu); |
Arnd Bergmann | 3830734 | 2005-12-09 19:04:18 +0100 | [diff] [blame] | 213 | if (stat & 2) /* mapping fault */ |
Arnd Bergmann | f0831ac | 2006-01-04 20:31:30 +0100 | [diff] [blame] | 214 | spu_mfc_dsisr_set(spu, 0ul); |
| 215 | spu_int_stat_clear(spu, 1, stat); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 216 | spin_unlock(&spu->register_lock); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 217 | pr_debug("%s: %lx %lx %lx %lx\n", __FUNCTION__, mask, stat, |
| 218 | dar, dsisr); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 219 | |
| 220 | if (stat & 1) /* segment fault */ |
| 221 | __spu_trap_data_seg(spu, dar); |
| 222 | |
| 223 | if (stat & 2) { /* mapping fault */ |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 224 | __spu_trap_data_map(spu, dar, dsisr); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | if (stat & 4) /* ls compare & suspend on get */ |
| 228 | ; |
| 229 | |
| 230 | if (stat & 8) /* ls compare & suspend on put */ |
| 231 | ; |
| 232 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 233 | return stat ? IRQ_HANDLED : IRQ_NONE; |
| 234 | } |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 235 | EXPORT_SYMBOL_GPL(spu_irq_class_1_bottom); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 236 | |
| 237 | static irqreturn_t |
Olaf Hering | f5a9245 | 2006-10-06 22:52:16 +0200 | [diff] [blame] | 238 | spu_irq_class_2(int irq, void *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 239 | { |
| 240 | struct spu *spu; |
| 241 | unsigned long stat; |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 242 | unsigned long mask; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 243 | |
| 244 | spu = data; |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 245 | spin_lock(&spu->register_lock); |
Arnd Bergmann | f0831ac | 2006-01-04 20:31:30 +0100 | [diff] [blame] | 246 | stat = spu_int_stat_get(spu, 2); |
| 247 | mask = spu_int_mask_get(spu, 2); |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 248 | /* ignore interrupts we're not waiting for */ |
| 249 | stat &= mask; |
| 250 | /* |
| 251 | * mailbox interrupts (0x1 and 0x10) are level triggered. |
| 252 | * mask them now before acknowledging. |
| 253 | */ |
| 254 | if (stat & 0x11) |
| 255 | spu_int_mask_and(spu, 2, ~(stat & 0x11)); |
| 256 | /* acknowledge all interrupts before the callbacks */ |
| 257 | spu_int_stat_clear(spu, 2, stat); |
| 258 | spin_unlock(&spu->register_lock); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 259 | |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 260 | pr_debug("class 2 interrupt %d, %lx, %lx\n", irq, stat, mask); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 261 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 262 | if (stat & 1) /* PPC core mailbox */ |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 263 | spu->ibox_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 264 | |
| 265 | if (stat & 2) /* SPU stop-and-signal */ |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 266 | spu->stop_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 267 | |
| 268 | if (stat & 4) /* SPU halted */ |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 269 | spu->stop_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 270 | |
| 271 | if (stat & 8) /* DMA tag group complete */ |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 272 | spu->mfc_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 273 | |
| 274 | if (stat & 0x10) /* SPU mailbox threshold */ |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 275 | spu->wbox_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 276 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 277 | return stat ? IRQ_HANDLED : IRQ_NONE; |
| 278 | } |
| 279 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 280 | static int spu_request_irqs(struct spu *spu) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 281 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 282 | int ret = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 283 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 284 | if (spu->irqs[0] != NO_IRQ) { |
| 285 | snprintf(spu->irq_c0, sizeof (spu->irq_c0), "spe%02d.0", |
| 286 | spu->number); |
| 287 | ret = request_irq(spu->irqs[0], spu_irq_class_0, |
| 288 | IRQF_DISABLED, |
| 289 | spu->irq_c0, spu); |
| 290 | if (ret) |
| 291 | goto bail0; |
| 292 | } |
| 293 | if (spu->irqs[1] != NO_IRQ) { |
| 294 | snprintf(spu->irq_c1, sizeof (spu->irq_c1), "spe%02d.1", |
| 295 | spu->number); |
| 296 | ret = request_irq(spu->irqs[1], spu_irq_class_1, |
| 297 | IRQF_DISABLED, |
| 298 | spu->irq_c1, spu); |
| 299 | if (ret) |
| 300 | goto bail1; |
| 301 | } |
| 302 | if (spu->irqs[2] != NO_IRQ) { |
| 303 | snprintf(spu->irq_c2, sizeof (spu->irq_c2), "spe%02d.2", |
| 304 | spu->number); |
| 305 | ret = request_irq(spu->irqs[2], spu_irq_class_2, |
| 306 | IRQF_DISABLED, |
| 307 | spu->irq_c2, spu); |
| 308 | if (ret) |
| 309 | goto bail2; |
| 310 | } |
| 311 | return 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 312 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 313 | bail2: |
| 314 | if (spu->irqs[1] != NO_IRQ) |
| 315 | free_irq(spu->irqs[1], spu); |
| 316 | bail1: |
| 317 | if (spu->irqs[0] != NO_IRQ) |
| 318 | free_irq(spu->irqs[0], spu); |
| 319 | bail0: |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 320 | return ret; |
| 321 | } |
| 322 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 323 | static void spu_free_irqs(struct spu *spu) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 324 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 325 | if (spu->irqs[0] != NO_IRQ) |
| 326 | free_irq(spu->irqs[0], spu); |
| 327 | if (spu->irqs[1] != NO_IRQ) |
| 328 | free_irq(spu->irqs[1], spu); |
| 329 | if (spu->irqs[2] != NO_IRQ) |
| 330 | free_irq(spu->irqs[2], spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 331 | } |
| 332 | |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 333 | static struct list_head spu_list[MAX_NUMNODES]; |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 334 | static LIST_HEAD(spu_full_list); |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 335 | static DEFINE_MUTEX(spu_mutex); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 336 | |
| 337 | static void spu_init_channels(struct spu *spu) |
| 338 | { |
| 339 | static const struct { |
| 340 | unsigned channel; |
| 341 | unsigned count; |
| 342 | } zero_list[] = { |
| 343 | { 0x00, 1, }, { 0x01, 1, }, { 0x03, 1, }, { 0x04, 1, }, |
| 344 | { 0x18, 1, }, { 0x19, 1, }, { 0x1b, 1, }, { 0x1d, 1, }, |
| 345 | }, count_list[] = { |
| 346 | { 0x00, 0, }, { 0x03, 0, }, { 0x04, 0, }, { 0x15, 16, }, |
| 347 | { 0x17, 1, }, { 0x18, 0, }, { 0x19, 0, }, { 0x1b, 0, }, |
| 348 | { 0x1c, 1, }, { 0x1d, 0, }, { 0x1e, 1, }, |
| 349 | }; |
Arnd Bergmann | 6ff730c | 2006-01-04 20:31:31 +0100 | [diff] [blame] | 350 | struct spu_priv2 __iomem *priv2; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 351 | int i; |
| 352 | |
| 353 | priv2 = spu->priv2; |
| 354 | |
| 355 | /* initialize all channel data to zero */ |
| 356 | for (i = 0; i < ARRAY_SIZE(zero_list); i++) { |
| 357 | int count; |
| 358 | |
| 359 | out_be64(&priv2->spu_chnlcntptr_RW, zero_list[i].channel); |
| 360 | for (count = 0; count < zero_list[i].count; count++) |
| 361 | out_be64(&priv2->spu_chnldata_RW, 0); |
| 362 | } |
| 363 | |
| 364 | /* initialize channel counts to meaningful values */ |
| 365 | for (i = 0; i < ARRAY_SIZE(count_list); i++) { |
| 366 | out_be64(&priv2->spu_chnlcntptr_RW, count_list[i].channel); |
| 367 | out_be64(&priv2->spu_chnlcnt_RW, count_list[i].count); |
| 368 | } |
| 369 | } |
| 370 | |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 371 | struct spu *spu_alloc_node(int node) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 372 | { |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 373 | struct spu *spu = NULL; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 374 | |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 375 | mutex_lock(&spu_mutex); |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 376 | if (!list_empty(&spu_list[node])) { |
| 377 | spu = list_entry(spu_list[node].next, struct spu, list); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 378 | list_del_init(&spu->list); |
Geoff Levand | cc21a66 | 2006-10-24 18:31:15 +0200 | [diff] [blame] | 379 | pr_debug("Got SPU %d %d\n", spu->number, spu->node); |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 380 | spu_init_channels(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 381 | } |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 382 | mutex_unlock(&spu_mutex); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 383 | |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 384 | return spu; |
| 385 | } |
| 386 | EXPORT_SYMBOL_GPL(spu_alloc_node); |
| 387 | |
| 388 | struct spu *spu_alloc(void) |
| 389 | { |
| 390 | struct spu *spu = NULL; |
| 391 | int node; |
| 392 | |
| 393 | for (node = 0; node < MAX_NUMNODES; node++) { |
| 394 | spu = spu_alloc_node(node); |
| 395 | if (spu) |
| 396 | break; |
| 397 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 398 | |
| 399 | return spu; |
| 400 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 401 | |
| 402 | void spu_free(struct spu *spu) |
| 403 | { |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 404 | mutex_lock(&spu_mutex); |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 405 | list_add_tail(&spu->list, &spu_list[spu->node]); |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 406 | mutex_unlock(&spu_mutex); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 407 | } |
Arnd Bergmann | 39c73c3 | 2005-12-05 22:52:21 -0500 | [diff] [blame] | 408 | EXPORT_SYMBOL_GPL(spu_free); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 409 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 410 | static int spu_handle_mm_fault(struct spu *spu) |
| 411 | { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 412 | struct mm_struct *mm = spu->mm; |
| 413 | struct vm_area_struct *vma; |
| 414 | u64 ea, dsisr, is_write; |
| 415 | int ret; |
| 416 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 417 | ea = spu->dar; |
| 418 | dsisr = spu->dsisr; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 419 | #if 0 |
| 420 | if (!IS_VALID_EA(ea)) { |
| 421 | return -EFAULT; |
| 422 | } |
| 423 | #endif /* XXX */ |
| 424 | if (mm == NULL) { |
| 425 | return -EFAULT; |
| 426 | } |
| 427 | if (mm->pgd == NULL) { |
| 428 | return -EFAULT; |
| 429 | } |
| 430 | |
| 431 | down_read(&mm->mmap_sem); |
| 432 | vma = find_vma(mm, ea); |
| 433 | if (!vma) |
| 434 | goto bad_area; |
| 435 | if (vma->vm_start <= ea) |
| 436 | goto good_area; |
| 437 | if (!(vma->vm_flags & VM_GROWSDOWN)) |
| 438 | goto bad_area; |
| 439 | #if 0 |
| 440 | if (expand_stack(vma, ea)) |
| 441 | goto bad_area; |
| 442 | #endif /* XXX */ |
| 443 | good_area: |
| 444 | is_write = dsisr & MFC_DSISR_ACCESS_PUT; |
| 445 | if (is_write) { |
| 446 | if (!(vma->vm_flags & VM_WRITE)) |
| 447 | goto bad_area; |
| 448 | } else { |
| 449 | if (dsisr & MFC_DSISR_ACCESS_DENIED) |
| 450 | goto bad_area; |
| 451 | if (!(vma->vm_flags & (VM_READ | VM_EXEC))) |
| 452 | goto bad_area; |
| 453 | } |
| 454 | ret = 0; |
| 455 | switch (handle_mm_fault(mm, vma, ea, is_write)) { |
| 456 | case VM_FAULT_MINOR: |
| 457 | current->min_flt++; |
| 458 | break; |
| 459 | case VM_FAULT_MAJOR: |
| 460 | current->maj_flt++; |
| 461 | break; |
| 462 | case VM_FAULT_SIGBUS: |
| 463 | ret = -EFAULT; |
| 464 | goto bad_area; |
| 465 | case VM_FAULT_OOM: |
| 466 | ret = -ENOMEM; |
| 467 | goto bad_area; |
| 468 | default: |
| 469 | BUG(); |
| 470 | } |
| 471 | up_read(&mm->mmap_sem); |
| 472 | return ret; |
| 473 | |
| 474 | bad_area: |
| 475 | up_read(&mm->mmap_sem); |
| 476 | return -EFAULT; |
| 477 | } |
| 478 | |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 479 | int spu_irq_class_1_bottom(struct spu *spu) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 480 | { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 481 | u64 ea, dsisr, access, error = 0UL; |
| 482 | int ret = 0; |
| 483 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 484 | ea = spu->dar; |
| 485 | dsisr = spu->dsisr; |
Arnd Bergmann | 79c227a | 2006-03-24 19:49:27 +0100 | [diff] [blame] | 486 | if (dsisr & (MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED)) { |
Arnd Bergmann | f807221 | 2006-04-29 02:40:21 +0200 | [diff] [blame] | 487 | u64 flags; |
| 488 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 489 | access = (_PAGE_PRESENT | _PAGE_USER); |
| 490 | access |= (dsisr & MFC_DSISR_ACCESS_PUT) ? _PAGE_RW : 0UL; |
Arnd Bergmann | f807221 | 2006-04-29 02:40:21 +0200 | [diff] [blame] | 491 | local_irq_save(flags); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 492 | if (hash_page(ea, access, 0x300) != 0) |
| 493 | error |= CLASS1_ENABLE_STORAGE_FAULT_INTR; |
Arnd Bergmann | f807221 | 2006-04-29 02:40:21 +0200 | [diff] [blame] | 494 | local_irq_restore(flags); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 495 | } |
Arnd Bergmann | 79c227a | 2006-03-24 19:49:27 +0100 | [diff] [blame] | 496 | if (error & CLASS1_ENABLE_STORAGE_FAULT_INTR) { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 497 | if ((ret = spu_handle_mm_fault(spu)) != 0) |
| 498 | error |= CLASS1_ENABLE_STORAGE_FAULT_INTR; |
| 499 | else |
| 500 | error &= ~CLASS1_ENABLE_STORAGE_FAULT_INTR; |
| 501 | } |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 502 | spu->dar = 0UL; |
| 503 | spu->dsisr = 0UL; |
| 504 | if (!error) { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 505 | spu_restart_dma(spu); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 506 | } else { |
Arnd Bergmann | 453d9f7 | 2006-11-20 18:45:03 +0100 | [diff] [blame] | 507 | spu->dma_callback(spu, SPE_EVENT_SPE_DATA_STORAGE); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 508 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 509 | return ret; |
| 510 | } |
| 511 | |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 512 | struct sysdev_class spu_sysdev_class = { |
| 513 | set_kset_name("spu") |
| 514 | }; |
| 515 | |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 516 | int spu_add_sysdev_attr(struct sysdev_attribute *attr) |
| 517 | { |
| 518 | struct spu *spu; |
| 519 | mutex_lock(&spu_mutex); |
| 520 | |
| 521 | list_for_each_entry(spu, &spu_full_list, full_list) |
| 522 | sysdev_create_file(&spu->sysdev, attr); |
| 523 | |
| 524 | mutex_unlock(&spu_mutex); |
| 525 | return 0; |
| 526 | } |
| 527 | EXPORT_SYMBOL_GPL(spu_add_sysdev_attr); |
| 528 | |
| 529 | int spu_add_sysdev_attr_group(struct attribute_group *attrs) |
| 530 | { |
| 531 | struct spu *spu; |
| 532 | mutex_lock(&spu_mutex); |
| 533 | |
| 534 | list_for_each_entry(spu, &spu_full_list, full_list) |
| 535 | sysfs_create_group(&spu->sysdev.kobj, attrs); |
| 536 | |
| 537 | mutex_unlock(&spu_mutex); |
| 538 | return 0; |
| 539 | } |
| 540 | EXPORT_SYMBOL_GPL(spu_add_sysdev_attr_group); |
| 541 | |
| 542 | |
| 543 | void spu_remove_sysdev_attr(struct sysdev_attribute *attr) |
| 544 | { |
| 545 | struct spu *spu; |
| 546 | mutex_lock(&spu_mutex); |
| 547 | |
| 548 | list_for_each_entry(spu, &spu_full_list, full_list) |
| 549 | sysdev_remove_file(&spu->sysdev, attr); |
| 550 | |
| 551 | mutex_unlock(&spu_mutex); |
| 552 | } |
| 553 | EXPORT_SYMBOL_GPL(spu_remove_sysdev_attr); |
| 554 | |
| 555 | void spu_remove_sysdev_attr_group(struct attribute_group *attrs) |
| 556 | { |
| 557 | struct spu *spu; |
| 558 | mutex_lock(&spu_mutex); |
| 559 | |
| 560 | list_for_each_entry(spu, &spu_full_list, full_list) |
| 561 | sysfs_remove_group(&spu->sysdev.kobj, attrs); |
| 562 | |
| 563 | mutex_unlock(&spu_mutex); |
| 564 | } |
| 565 | EXPORT_SYMBOL_GPL(spu_remove_sysdev_attr_group); |
| 566 | |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 567 | static int spu_create_sysdev(struct spu *spu) |
| 568 | { |
| 569 | int ret; |
| 570 | |
| 571 | spu->sysdev.id = spu->number; |
| 572 | spu->sysdev.cls = &spu_sysdev_class; |
| 573 | ret = sysdev_register(&spu->sysdev); |
| 574 | if (ret) { |
| 575 | printk(KERN_ERR "Can't register SPU %d with sysfs\n", |
| 576 | spu->number); |
| 577 | return ret; |
| 578 | } |
| 579 | |
Geoff Levand | 0021550 | 2006-11-20 18:45:02 +0100 | [diff] [blame] | 580 | sysfs_add_device_to_node(&spu->sysdev, spu->node); |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | static void spu_destroy_sysdev(struct spu *spu) |
| 586 | { |
Geoff Levand | 0021550 | 2006-11-20 18:45:02 +0100 | [diff] [blame] | 587 | sysfs_remove_device_from_node(&spu->sysdev, spu->node); |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 588 | sysdev_unregister(&spu->sysdev); |
| 589 | } |
| 590 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 591 | static int __init create_spu(void *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 592 | { |
| 593 | struct spu *spu; |
| 594 | int ret; |
| 595 | static int number; |
| 596 | |
| 597 | ret = -ENOMEM; |
Jeremy Kerr | ecec217 | 2006-06-19 20:33:26 +0200 | [diff] [blame] | 598 | spu = kzalloc(sizeof (*spu), GFP_KERNEL); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 599 | if (!spu) |
| 600 | goto out; |
| 601 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 602 | spin_lock_init(&spu->register_lock); |
| 603 | mutex_lock(&spu_mutex); |
| 604 | spu->number = number++; |
| 605 | mutex_unlock(&spu_mutex); |
Benjamin Herrenschmidt | e5267b4 | 2006-10-10 15:14:12 +1000 | [diff] [blame] | 606 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 607 | ret = spu_create_spu(spu, data); |
| 608 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 609 | if (ret) |
| 610 | goto out_free; |
| 611 | |
Masato Noguchi | 24f43b3 | 2006-10-24 18:31:14 +0200 | [diff] [blame] | 612 | spu_mfc_sdr_setup(spu); |
Arnd Bergmann | f0831ac | 2006-01-04 20:31:30 +0100 | [diff] [blame] | 613 | spu_mfc_sr1_set(spu, 0x33); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 614 | ret = spu_request_irqs(spu); |
| 615 | if (ret) |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 616 | goto out_destroy; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 617 | |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 618 | ret = spu_create_sysdev(spu); |
| 619 | if (ret) |
| 620 | goto out_free_irqs; |
| 621 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 622 | mutex_lock(&spu_mutex); |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 623 | list_add(&spu->list, &spu_list[spu->node]); |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 624 | list_add(&spu->full_list, &spu_full_list); |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 625 | mutex_unlock(&spu_mutex); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 626 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 627 | goto out; |
| 628 | |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 629 | out_free_irqs: |
| 630 | spu_free_irqs(spu); |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 631 | out_destroy: |
| 632 | spu_destroy_spu(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 633 | out_free: |
| 634 | kfree(spu); |
| 635 | out: |
| 636 | return ret; |
| 637 | } |
| 638 | |
| 639 | static void destroy_spu(struct spu *spu) |
| 640 | { |
| 641 | list_del_init(&spu->list); |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 642 | list_del_init(&spu->full_list); |
| 643 | |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 644 | spu_destroy_sysdev(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 645 | spu_free_irqs(spu); |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 646 | spu_destroy_spu(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 647 | kfree(spu); |
| 648 | } |
| 649 | |
| 650 | static void cleanup_spu_base(void) |
| 651 | { |
| 652 | struct spu *spu, *tmp; |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 653 | int node; |
| 654 | |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 655 | mutex_lock(&spu_mutex); |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 656 | for (node = 0; node < MAX_NUMNODES; node++) { |
| 657 | list_for_each_entry_safe(spu, tmp, &spu_list[node], list) |
| 658 | destroy_spu(spu); |
| 659 | } |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 660 | mutex_unlock(&spu_mutex); |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 661 | sysdev_class_unregister(&spu_sysdev_class); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 662 | } |
| 663 | module_exit(cleanup_spu_base); |
| 664 | |
| 665 | static int __init init_spu_base(void) |
| 666 | { |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 667 | int i, ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 668 | |
Stephen Rothwell | da06aa0 | 2006-11-27 19:18:54 +0100 | [diff] [blame] | 669 | if (!spu_management_ops) |
| 670 | return 0; |
| 671 | |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 672 | /* create sysdev class for spus */ |
| 673 | ret = sysdev_class_register(&spu_sysdev_class); |
| 674 | if (ret) |
| 675 | return ret; |
| 676 | |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 677 | for (i = 0; i < MAX_NUMNODES; i++) |
| 678 | INIT_LIST_HEAD(&spu_list[i]); |
| 679 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 680 | ret = spu_enumerate_spus(create_spu); |
| 681 | |
| 682 | if (ret) { |
| 683 | printk(KERN_WARNING "%s: Error initializing spus\n", |
| 684 | __FUNCTION__); |
| 685 | cleanup_spu_base(); |
| 686 | return ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 687 | } |
Michael Ellerman | ff8a8f2 | 2006-10-24 18:31:27 +0200 | [diff] [blame] | 688 | |
| 689 | xmon_register_spus(&spu_full_list); |
| 690 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 691 | return ret; |
| 692 | } |
| 693 | module_init(init_spu_base); |
| 694 | |
| 695 | MODULE_LICENSE("GPL"); |
| 696 | MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>"); |