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