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> |
Geert Uytterhoeven | bce9451 | 2007-07-17 04:05:52 -0700 | [diff] [blame] | 34 | #include <linux/linux_logo.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 35 | #include <asm/spu.h> |
Geoff Levand | 540270d | 2006-06-19 20:33:29 +0200 | [diff] [blame] | 36 | #include <asm/spu_priv1.h> |
Jeremy Kerr | 58bd403 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 37 | #include <asm/spu_csa.h> |
Michael Ellerman | ff8a8f2 | 2006-10-24 18:31:27 +0200 | [diff] [blame] | 38 | #include <asm/xmon.h> |
Arnd Bergmann | 3ad216c | 2007-07-20 21:39:46 +0200 | [diff] [blame] | 39 | #include <asm/prom.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 40 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 41 | const struct spu_management_ops *spu_management_ops; |
Jeremy Kerr | ccf17e9 | 2007-04-23 21:08:29 +0200 | [diff] [blame] | 42 | EXPORT_SYMBOL_GPL(spu_management_ops); |
| 43 | |
Geoff Levand | 540270d | 2006-06-19 20:33:29 +0200 | [diff] [blame] | 44 | const struct spu_priv1_ops *spu_priv1_ops; |
Geoff Levand | 540270d | 2006-06-19 20:33:29 +0200 | [diff] [blame] | 45 | EXPORT_SYMBOL_GPL(spu_priv1_ops); |
| 46 | |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 47 | struct cbe_spu_info cbe_spu_info[MAX_NUMNODES]; |
| 48 | EXPORT_SYMBOL_GPL(cbe_spu_info); |
| 49 | |
| 50 | /* |
Jeremy Kerr | 3ce2f62 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 51 | * The spufs fault-handling code needs to call force_sig_info to raise signals |
| 52 | * on DMA errors. Export it here to avoid general kernel-wide access to this |
| 53 | * function |
| 54 | */ |
| 55 | EXPORT_SYMBOL_GPL(force_sig_info); |
| 56 | |
| 57 | /* |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 58 | * Protects cbe_spu_info and spu->number. |
| 59 | */ |
| 60 | static DEFINE_SPINLOCK(spu_lock); |
| 61 | |
| 62 | /* |
| 63 | * List of all spus in the system. |
| 64 | * |
| 65 | * This list is iterated by callers from irq context and callers that |
| 66 | * want to sleep. Thus modifications need to be done with both |
| 67 | * spu_full_list_lock and spu_full_list_mutex held, while iterating |
| 68 | * through it requires either of these locks. |
| 69 | * |
| 70 | * In addition spu_full_list_lock protects all assignmens to |
| 71 | * spu->mm. |
| 72 | */ |
| 73 | static LIST_HEAD(spu_full_list); |
| 74 | static DEFINE_SPINLOCK(spu_full_list_lock); |
| 75 | static DEFINE_MUTEX(spu_full_list_mutex); |
| 76 | |
Jeremy Kerr | 58bd403 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 77 | struct spu_slb { |
| 78 | u64 esid, vsid; |
| 79 | }; |
| 80 | |
Benjamin Herrenschmidt | 94b2a43 | 2007-03-10 00:05:37 +0100 | [diff] [blame] | 81 | void spu_invalidate_slbs(struct spu *spu) |
| 82 | { |
| 83 | struct spu_priv2 __iomem *priv2 = spu->priv2; |
| 84 | |
| 85 | if (spu_mfc_sr1_get(spu) & MFC_STATE1_RELOCATE_MASK) |
| 86 | out_be64(&priv2->slb_invalidate_all_W, 0UL); |
| 87 | } |
| 88 | EXPORT_SYMBOL_GPL(spu_invalidate_slbs); |
| 89 | |
| 90 | /* This is called by the MM core when a segment size is changed, to |
| 91 | * request a flush of all the SPEs using a given mm |
| 92 | */ |
| 93 | void spu_flush_all_slbs(struct mm_struct *mm) |
| 94 | { |
| 95 | struct spu *spu; |
| 96 | unsigned long flags; |
| 97 | |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 98 | spin_lock_irqsave(&spu_full_list_lock, flags); |
Benjamin Herrenschmidt | 94b2a43 | 2007-03-10 00:05:37 +0100 | [diff] [blame] | 99 | list_for_each_entry(spu, &spu_full_list, full_list) { |
| 100 | if (spu->mm == mm) |
| 101 | spu_invalidate_slbs(spu); |
| 102 | } |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 103 | spin_unlock_irqrestore(&spu_full_list_lock, flags); |
Benjamin Herrenschmidt | 94b2a43 | 2007-03-10 00:05:37 +0100 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /* The hack below stinks... try to do something better one of |
| 107 | * these days... Does it even work properly with NR_CPUS == 1 ? |
| 108 | */ |
| 109 | static inline void mm_needs_global_tlbie(struct mm_struct *mm) |
| 110 | { |
| 111 | int nr = (NR_CPUS > 1) ? NR_CPUS : NR_CPUS + 1; |
| 112 | |
| 113 | /* Global TLBIE broadcast required with SPEs. */ |
| 114 | __cpus_setall(&mm->cpu_vm_mask, nr); |
| 115 | } |
| 116 | |
| 117 | void spu_associate_mm(struct spu *spu, struct mm_struct *mm) |
| 118 | { |
| 119 | unsigned long flags; |
| 120 | |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 121 | spin_lock_irqsave(&spu_full_list_lock, flags); |
Benjamin Herrenschmidt | 94b2a43 | 2007-03-10 00:05:37 +0100 | [diff] [blame] | 122 | spu->mm = mm; |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 123 | spin_unlock_irqrestore(&spu_full_list_lock, flags); |
Benjamin Herrenschmidt | 94b2a43 | 2007-03-10 00:05:37 +0100 | [diff] [blame] | 124 | if (mm) |
| 125 | mm_needs_global_tlbie(mm); |
| 126 | } |
| 127 | EXPORT_SYMBOL_GPL(spu_associate_mm); |
| 128 | |
Jeremy Kerr | f6eb7d7f | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 129 | int spu_64k_pages_available(void) |
| 130 | { |
| 131 | return mmu_psize_defs[MMU_PAGE_64K].shift != 0; |
| 132 | } |
| 133 | EXPORT_SYMBOL_GPL(spu_64k_pages_available); |
| 134 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 135 | static int __spu_trap_invalid_dma(struct spu *spu) |
| 136 | { |
| 137 | pr_debug("%s\n", __FUNCTION__); |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 138 | spu->dma_callback(spu, SPE_EVENT_INVALID_DMA); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static int __spu_trap_dma_align(struct spu *spu) |
| 143 | { |
| 144 | pr_debug("%s\n", __FUNCTION__); |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 145 | spu->dma_callback(spu, SPE_EVENT_DMA_ALIGNMENT); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static int __spu_trap_error(struct spu *spu) |
| 150 | { |
| 151 | pr_debug("%s\n", __FUNCTION__); |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 152 | spu->dma_callback(spu, SPE_EVENT_SPE_ERROR); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static void spu_restart_dma(struct spu *spu) |
| 157 | { |
| 158 | struct spu_priv2 __iomem *priv2 = spu->priv2; |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 159 | |
Arnd Bergmann | 8837d92 | 2006-01-04 20:31:28 +0100 | [diff] [blame] | 160 | if (!test_bit(SPU_CONTEXT_SWITCH_PENDING, &spu->flags)) |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 161 | out_be64(&priv2->mfc_control_RW, MFC_CNTL_RESTART_DMA_COMMAND); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Jeremy Kerr | 58bd403 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 164 | static inline void spu_load_slb(struct spu *spu, int slbe, struct spu_slb *slb) |
| 165 | { |
| 166 | struct spu_priv2 __iomem *priv2 = spu->priv2; |
| 167 | |
| 168 | pr_debug("%s: adding SLB[%d] 0x%016lx 0x%016lx\n", |
| 169 | __func__, slbe, slb->vsid, slb->esid); |
| 170 | |
| 171 | out_be64(&priv2->slb_index_W, slbe); |
| 172 | out_be64(&priv2->slb_vsid_RW, slb->vsid); |
| 173 | out_be64(&priv2->slb_esid_RW, slb->esid); |
| 174 | } |
| 175 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 176 | static int __spu_trap_data_seg(struct spu *spu, unsigned long ea) |
| 177 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 178 | struct mm_struct *mm = spu->mm; |
Jeremy Kerr | 4d43466 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 179 | struct spu_slb slb; |
Benjamin Herrenschmidt | 94b2a43 | 2007-03-10 00:05:37 +0100 | [diff] [blame] | 180 | int psize; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 181 | |
| 182 | pr_debug("%s\n", __FUNCTION__); |
| 183 | |
Arnd Bergmann | 8837d92 | 2006-01-04 20:31:28 +0100 | [diff] [blame] | 184 | if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 185 | /* SLBs are pre-loaded for context switch, so |
| 186 | * we should never get here! |
| 187 | */ |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 188 | printk("%s: invalid access during switch!\n", __func__); |
| 189 | return 1; |
| 190 | } |
Jeremy Kerr | 4d43466 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 191 | slb.esid = (ea & ESID_MASK) | SLB_ESID_V; |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 192 | |
| 193 | switch(REGION_ID(ea)) { |
| 194 | case USER_REGION_ID: |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 195 | #ifdef CONFIG_PPC_MM_SLICES |
| 196 | psize = get_slice_psize(mm, ea); |
| 197 | #else |
| 198 | psize = mm->context.user_psize; |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 199 | #endif |
Jeremy Kerr | 4d43466 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 200 | slb.vsid = (get_vsid(mm->context.id, ea, MMU_SEGSIZE_256M) |
| 201 | << SLB_VSID_SHIFT) | SLB_VSID_USER; |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 202 | break; |
| 203 | case VMALLOC_REGION_ID: |
Benjamin Herrenschmidt | 94b2a43 | 2007-03-10 00:05:37 +0100 | [diff] [blame] | 204 | if (ea < VMALLOC_END) |
| 205 | psize = mmu_vmalloc_psize; |
| 206 | else |
| 207 | psize = mmu_io_psize; |
Jeremy Kerr | 4d43466 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 208 | slb.vsid = (get_kernel_vsid(ea, MMU_SEGSIZE_256M) |
| 209 | << SLB_VSID_SHIFT) | SLB_VSID_KERNEL; |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 210 | break; |
| 211 | case KERNEL_REGION_ID: |
Benjamin Herrenschmidt | 94b2a43 | 2007-03-10 00:05:37 +0100 | [diff] [blame] | 212 | psize = mmu_linear_psize; |
Jeremy Kerr | 4d43466 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 213 | slb.vsid = (get_kernel_vsid(ea, MMU_SEGSIZE_256M) |
| 214 | << SLB_VSID_SHIFT) | SLB_VSID_KERNEL; |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 215 | break; |
| 216 | default: |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 217 | /* Future: support kernel segments so that drivers |
| 218 | * can use SPUs. |
| 219 | */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 220 | pr_debug("invalid region access at %016lx\n", ea); |
| 221 | return 1; |
| 222 | } |
Jeremy Kerr | 4d43466 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 223 | slb.vsid |= mmu_psize_defs[psize].sllp; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 224 | |
Jeremy Kerr | 4d43466 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 225 | spu_load_slb(spu, spu->slb_replace, &slb); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 226 | |
| 227 | spu->slb_replace++; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 228 | if (spu->slb_replace >= 8) |
| 229 | spu->slb_replace = 0; |
| 230 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 231 | spu_restart_dma(spu); |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 232 | spu->stats.slb_flt++; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 233 | return 0; |
| 234 | } |
| 235 | |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 236 | 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] | 237 | 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] | 238 | { |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 239 | pr_debug("%s, %lx, %lx\n", __FUNCTION__, dsisr, ea); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 240 | |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 241 | /* Handle kernel space hash faults immediately. |
| 242 | User hash faults need to be deferred to process context. */ |
| 243 | if ((dsisr & MFC_DSISR_PTE_NOT_FOUND) |
| 244 | && REGION_ID(ea) != USER_REGION_ID |
| 245 | && hash_page(ea, _PAGE_PRESENT, 0x300) == 0) { |
| 246 | spu_restart_dma(spu); |
| 247 | return 0; |
| 248 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 249 | |
Arnd Bergmann | 8837d92 | 2006-01-04 20:31:28 +0100 | [diff] [blame] | 250 | if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) { |
Mark Nutter | 5473af0 | 2005-11-15 15:53:49 -0500 | [diff] [blame] | 251 | printk("%s: invalid access during switch!\n", __func__); |
| 252 | return 1; |
| 253 | } |
| 254 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 255 | spu->dar = ea; |
| 256 | spu->dsisr = dsisr; |
| 257 | mb(); |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 258 | spu->stop_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | |
Jeremy Kerr | 58bd403 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 262 | static void __spu_kernel_slb(void *addr, struct spu_slb *slb) |
| 263 | { |
| 264 | unsigned long ea = (unsigned long)addr; |
| 265 | u64 llp; |
| 266 | |
| 267 | if (REGION_ID(ea) == KERNEL_REGION_ID) |
| 268 | llp = mmu_psize_defs[mmu_linear_psize].sllp; |
| 269 | else |
| 270 | llp = mmu_psize_defs[mmu_virtual_psize].sllp; |
| 271 | |
| 272 | slb->vsid = (get_kernel_vsid(ea, MMU_SEGSIZE_256M) << SLB_VSID_SHIFT) | |
| 273 | SLB_VSID_KERNEL | llp; |
| 274 | slb->esid = (ea & ESID_MASK) | SLB_ESID_V; |
| 275 | } |
| 276 | |
| 277 | /** |
Jeremy Kerr | 684bd61 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 278 | * Given an array of @nr_slbs SLB entries, @slbs, return non-zero if the |
| 279 | * address @new_addr is present. |
| 280 | */ |
| 281 | static inline int __slb_present(struct spu_slb *slbs, int nr_slbs, |
| 282 | void *new_addr) |
| 283 | { |
| 284 | unsigned long ea = (unsigned long)new_addr; |
| 285 | int i; |
| 286 | |
| 287 | for (i = 0; i < nr_slbs; i++) |
| 288 | if (!((slbs[i].esid ^ ea) & ESID_MASK)) |
| 289 | return 1; |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | /** |
Jeremy Kerr | 58bd403 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 295 | * Setup the SPU kernel SLBs, in preparation for a context save/restore. We |
| 296 | * need to map both the context save area, and the save/restore code. |
Jeremy Kerr | 684bd61 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 297 | * |
| 298 | * Because the lscsa and code may cross segment boundaires, we check to see |
| 299 | * if mappings are required for the start and end of each range. We currently |
| 300 | * assume that the mappings are smaller that one segment - if not, something |
| 301 | * is seriously wrong. |
Jeremy Kerr | 58bd403 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 302 | */ |
Jeremy Kerr | 684bd61 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 303 | void spu_setup_kernel_slbs(struct spu *spu, struct spu_lscsa *lscsa, |
| 304 | void *code, int code_size) |
Jeremy Kerr | 58bd403 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 305 | { |
Jeremy Kerr | 684bd61 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 306 | struct spu_slb slbs[4]; |
| 307 | int i, nr_slbs = 0; |
| 308 | /* start and end addresses of both mappings */ |
| 309 | void *addrs[] = { |
| 310 | lscsa, (void *)lscsa + sizeof(*lscsa) - 1, |
| 311 | code, code + code_size - 1 |
| 312 | }; |
Jeremy Kerr | 58bd403 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 313 | |
Jeremy Kerr | 684bd61 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 314 | /* check the set of addresses, and create a new entry in the slbs array |
| 315 | * if there isn't already a SLB for that address */ |
| 316 | for (i = 0; i < ARRAY_SIZE(addrs); i++) { |
| 317 | if (__slb_present(slbs, nr_slbs, addrs[i])) |
| 318 | continue; |
Jeremy Kerr | 58bd403 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 319 | |
Jeremy Kerr | 684bd61 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 320 | __spu_kernel_slb(addrs[i], &slbs[nr_slbs]); |
| 321 | nr_slbs++; |
| 322 | } |
| 323 | |
| 324 | /* Add the set of SLBs */ |
| 325 | for (i = 0; i < nr_slbs; i++) |
| 326 | spu_load_slb(spu, i, &slbs[i]); |
Jeremy Kerr | 58bd403 | 2007-12-05 13:49:31 +1100 | [diff] [blame] | 327 | } |
| 328 | EXPORT_SYMBOL_GPL(spu_setup_kernel_slbs); |
| 329 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 330 | static irqreturn_t |
Olaf Hering | f5a9245 | 2006-10-06 22:52:16 +0200 | [diff] [blame] | 331 | spu_irq_class_0(int irq, void *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 332 | { |
| 333 | struct spu *spu; |
Masato Noguchi | b7f90a4 | 2007-09-07 18:28:27 +1000 | [diff] [blame] | 334 | unsigned long stat, mask; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 335 | |
| 336 | spu = data; |
Masato Noguchi | b7f90a4 | 2007-09-07 18:28:27 +1000 | [diff] [blame] | 337 | |
| 338 | mask = spu_int_mask_get(spu, 0); |
| 339 | stat = spu_int_stat_get(spu, 0); |
| 340 | stat &= mask; |
| 341 | |
| 342 | spin_lock(&spu->register_lock); |
| 343 | spu->class_0_pending |= stat; |
| 344 | spin_unlock(&spu->register_lock); |
| 345 | |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 346 | spu->stop_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 347 | |
Masato Noguchi | b7f90a4 | 2007-09-07 18:28:27 +1000 | [diff] [blame] | 348 | spu_int_stat_clear(spu, 0, stat); |
| 349 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 350 | return IRQ_HANDLED; |
| 351 | } |
| 352 | |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 353 | int |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 354 | spu_irq_class_0_bottom(struct spu *spu) |
| 355 | { |
Ishizaki Kou | 3650cfe | 2007-01-12 09:52:41 +0900 | [diff] [blame] | 356 | unsigned long flags; |
Masato Noguchi | b7f90a4 | 2007-09-07 18:28:27 +1000 | [diff] [blame] | 357 | unsigned long stat; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 358 | |
Ishizaki Kou | 3650cfe | 2007-01-12 09:52:41 +0900 | [diff] [blame] | 359 | spin_lock_irqsave(&spu->register_lock, flags); |
Masato Noguchi | b7f90a4 | 2007-09-07 18:28:27 +1000 | [diff] [blame] | 360 | stat = spu->class_0_pending; |
| 361 | spu->class_0_pending = 0; |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 362 | |
Arnd Bergmann | 2cd90bc | 2006-06-23 20:57:50 +0200 | [diff] [blame] | 363 | if (stat & 1) /* invalid DMA alignment */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 364 | __spu_trap_dma_align(spu); |
| 365 | |
Arnd Bergmann | 2cd90bc | 2006-06-23 20:57:50 +0200 | [diff] [blame] | 366 | if (stat & 2) /* invalid MFC DMA */ |
| 367 | __spu_trap_invalid_dma(spu); |
| 368 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 369 | if (stat & 4) /* error on SPU */ |
| 370 | __spu_trap_error(spu); |
| 371 | |
Ishizaki Kou | 3650cfe | 2007-01-12 09:52:41 +0900 | [diff] [blame] | 372 | spin_unlock_irqrestore(&spu->register_lock, flags); |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 373 | |
| 374 | return (stat & 0x7) ? -EIO : 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 375 | } |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 376 | EXPORT_SYMBOL_GPL(spu_irq_class_0_bottom); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 377 | |
| 378 | static irqreturn_t |
Olaf Hering | f5a9245 | 2006-10-06 22:52:16 +0200 | [diff] [blame] | 379 | spu_irq_class_1(int irq, void *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 380 | { |
| 381 | struct spu *spu; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 382 | unsigned long stat, mask, dar, dsisr; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 383 | |
| 384 | spu = data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 385 | |
| 386 | /* atomically read & clear class1 status. */ |
| 387 | spin_lock(&spu->register_lock); |
Arnd Bergmann | f0831ac | 2006-01-04 20:31:30 +0100 | [diff] [blame] | 388 | mask = spu_int_mask_get(spu, 1); |
| 389 | stat = spu_int_stat_get(spu, 1) & mask; |
| 390 | dar = spu_mfc_dar_get(spu); |
| 391 | dsisr = spu_mfc_dsisr_get(spu); |
Arnd Bergmann | 3830734 | 2005-12-09 19:04:18 +0100 | [diff] [blame] | 392 | if (stat & 2) /* mapping fault */ |
Arnd Bergmann | f0831ac | 2006-01-04 20:31:30 +0100 | [diff] [blame] | 393 | spu_mfc_dsisr_set(spu, 0ul); |
| 394 | spu_int_stat_clear(spu, 1, stat); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 395 | spin_unlock(&spu->register_lock); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 396 | pr_debug("%s: %lx %lx %lx %lx\n", __FUNCTION__, mask, stat, |
| 397 | dar, dsisr); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 398 | |
| 399 | if (stat & 1) /* segment fault */ |
| 400 | __spu_trap_data_seg(spu, dar); |
| 401 | |
| 402 | if (stat & 2) { /* mapping fault */ |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 403 | __spu_trap_data_map(spu, dar, dsisr); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | if (stat & 4) /* ls compare & suspend on get */ |
| 407 | ; |
| 408 | |
| 409 | if (stat & 8) /* ls compare & suspend on put */ |
| 410 | ; |
| 411 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 412 | return stat ? IRQ_HANDLED : IRQ_NONE; |
| 413 | } |
| 414 | |
| 415 | static irqreturn_t |
Olaf Hering | f5a9245 | 2006-10-06 22:52:16 +0200 | [diff] [blame] | 416 | spu_irq_class_2(int irq, void *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 417 | { |
| 418 | struct spu *spu; |
| 419 | unsigned long stat; |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 420 | unsigned long mask; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 421 | |
| 422 | spu = data; |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 423 | spin_lock(&spu->register_lock); |
Arnd Bergmann | f0831ac | 2006-01-04 20:31:30 +0100 | [diff] [blame] | 424 | stat = spu_int_stat_get(spu, 2); |
| 425 | mask = spu_int_mask_get(spu, 2); |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 426 | /* ignore interrupts we're not waiting for */ |
| 427 | stat &= mask; |
| 428 | /* |
| 429 | * mailbox interrupts (0x1 and 0x10) are level triggered. |
| 430 | * mask them now before acknowledging. |
| 431 | */ |
| 432 | if (stat & 0x11) |
| 433 | spu_int_mask_and(spu, 2, ~(stat & 0x11)); |
| 434 | /* acknowledge all interrupts before the callbacks */ |
| 435 | spu_int_stat_clear(spu, 2, stat); |
| 436 | spin_unlock(&spu->register_lock); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 437 | |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 438 | pr_debug("class 2 interrupt %d, %lx, %lx\n", irq, stat, mask); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 439 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 440 | if (stat & 1) /* PPC core mailbox */ |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 441 | spu->ibox_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 442 | |
| 443 | if (stat & 2) /* SPU stop-and-signal */ |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 444 | spu->stop_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 445 | |
| 446 | if (stat & 4) /* SPU halted */ |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 447 | spu->stop_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 448 | |
| 449 | if (stat & 8) /* DMA tag group complete */ |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 450 | spu->mfc_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 451 | |
| 452 | if (stat & 0x10) /* SPU mailbox threshold */ |
Masato Noguchi | ba723fe2 | 2006-06-19 20:33:33 +0200 | [diff] [blame] | 453 | spu->wbox_callback(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 454 | |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 455 | spu->stats.class2_intr++; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 456 | return stat ? IRQ_HANDLED : IRQ_NONE; |
| 457 | } |
| 458 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 459 | static int spu_request_irqs(struct spu *spu) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 460 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 461 | int ret = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 462 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 463 | if (spu->irqs[0] != NO_IRQ) { |
| 464 | snprintf(spu->irq_c0, sizeof (spu->irq_c0), "spe%02d.0", |
| 465 | spu->number); |
| 466 | ret = request_irq(spu->irqs[0], spu_irq_class_0, |
| 467 | IRQF_DISABLED, |
| 468 | spu->irq_c0, spu); |
| 469 | if (ret) |
| 470 | goto bail0; |
| 471 | } |
| 472 | if (spu->irqs[1] != NO_IRQ) { |
| 473 | snprintf(spu->irq_c1, sizeof (spu->irq_c1), "spe%02d.1", |
| 474 | spu->number); |
| 475 | ret = request_irq(spu->irqs[1], spu_irq_class_1, |
| 476 | IRQF_DISABLED, |
| 477 | spu->irq_c1, spu); |
| 478 | if (ret) |
| 479 | goto bail1; |
| 480 | } |
| 481 | if (spu->irqs[2] != NO_IRQ) { |
| 482 | snprintf(spu->irq_c2, sizeof (spu->irq_c2), "spe%02d.2", |
| 483 | spu->number); |
| 484 | ret = request_irq(spu->irqs[2], spu_irq_class_2, |
| 485 | IRQF_DISABLED, |
| 486 | spu->irq_c2, spu); |
| 487 | if (ret) |
| 488 | goto bail2; |
| 489 | } |
| 490 | return 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 491 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 492 | bail2: |
| 493 | if (spu->irqs[1] != NO_IRQ) |
| 494 | free_irq(spu->irqs[1], spu); |
| 495 | bail1: |
| 496 | if (spu->irqs[0] != NO_IRQ) |
| 497 | free_irq(spu->irqs[0], spu); |
| 498 | bail0: |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 499 | return ret; |
| 500 | } |
| 501 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 502 | static void spu_free_irqs(struct spu *spu) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 503 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 504 | if (spu->irqs[0] != NO_IRQ) |
| 505 | free_irq(spu->irqs[0], spu); |
| 506 | if (spu->irqs[1] != NO_IRQ) |
| 507 | free_irq(spu->irqs[1], spu); |
| 508 | if (spu->irqs[2] != NO_IRQ) |
| 509 | free_irq(spu->irqs[2], spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 510 | } |
| 511 | |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 512 | void spu_init_channels(struct spu *spu) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 513 | { |
| 514 | static const struct { |
| 515 | unsigned channel; |
| 516 | unsigned count; |
| 517 | } zero_list[] = { |
| 518 | { 0x00, 1, }, { 0x01, 1, }, { 0x03, 1, }, { 0x04, 1, }, |
| 519 | { 0x18, 1, }, { 0x19, 1, }, { 0x1b, 1, }, { 0x1d, 1, }, |
| 520 | }, count_list[] = { |
| 521 | { 0x00, 0, }, { 0x03, 0, }, { 0x04, 0, }, { 0x15, 16, }, |
| 522 | { 0x17, 1, }, { 0x18, 0, }, { 0x19, 0, }, { 0x1b, 0, }, |
| 523 | { 0x1c, 1, }, { 0x1d, 0, }, { 0x1e, 1, }, |
| 524 | }; |
Arnd Bergmann | 6ff730c | 2006-01-04 20:31:31 +0100 | [diff] [blame] | 525 | struct spu_priv2 __iomem *priv2; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 526 | int i; |
| 527 | |
| 528 | priv2 = spu->priv2; |
| 529 | |
| 530 | /* initialize all channel data to zero */ |
| 531 | for (i = 0; i < ARRAY_SIZE(zero_list); i++) { |
| 532 | int count; |
| 533 | |
| 534 | out_be64(&priv2->spu_chnlcntptr_RW, zero_list[i].channel); |
| 535 | for (count = 0; count < zero_list[i].count; count++) |
| 536 | out_be64(&priv2->spu_chnldata_RW, 0); |
| 537 | } |
| 538 | |
| 539 | /* initialize channel counts to meaningful values */ |
| 540 | for (i = 0; i < ARRAY_SIZE(count_list); i++) { |
| 541 | out_be64(&priv2->spu_chnlcntptr_RW, count_list[i].channel); |
| 542 | out_be64(&priv2->spu_chnlcnt_RW, count_list[i].count); |
| 543 | } |
| 544 | } |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 545 | EXPORT_SYMBOL_GPL(spu_init_channels); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 546 | |
Geoff Levand | 6deac06 | 2007-06-16 07:17:32 +1000 | [diff] [blame] | 547 | static int spu_shutdown(struct sys_device *sysdev) |
| 548 | { |
| 549 | struct spu *spu = container_of(sysdev, struct spu, sysdev); |
| 550 | |
| 551 | spu_free_irqs(spu); |
| 552 | spu_destroy_spu(spu); |
| 553 | return 0; |
| 554 | } |
| 555 | |
Sebastian Siewior | 1238819 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 556 | static struct sysdev_class spu_sysdev_class = { |
Geoff Levand | 6deac06 | 2007-06-16 07:17:32 +1000 | [diff] [blame] | 557 | set_kset_name("spu"), |
| 558 | .shutdown = spu_shutdown, |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 559 | }; |
| 560 | |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 561 | int spu_add_sysdev_attr(struct sysdev_attribute *attr) |
| 562 | { |
| 563 | struct spu *spu; |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 564 | |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 565 | mutex_lock(&spu_full_list_mutex); |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 566 | list_for_each_entry(spu, &spu_full_list, full_list) |
| 567 | sysdev_create_file(&spu->sysdev, attr); |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 568 | mutex_unlock(&spu_full_list_mutex); |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 569 | |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 570 | return 0; |
| 571 | } |
| 572 | EXPORT_SYMBOL_GPL(spu_add_sysdev_attr); |
| 573 | |
| 574 | int spu_add_sysdev_attr_group(struct attribute_group *attrs) |
| 575 | { |
| 576 | struct spu *spu; |
Jeremy Kerr | 1e77103 | 2007-12-05 13:49:31 +1100 | [diff] [blame^] | 577 | int rc = 0; |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 578 | |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 579 | mutex_lock(&spu_full_list_mutex); |
Jeremy Kerr | 1e77103 | 2007-12-05 13:49:31 +1100 | [diff] [blame^] | 580 | list_for_each_entry(spu, &spu_full_list, full_list) { |
| 581 | rc = sysfs_create_group(&spu->sysdev.kobj, attrs); |
| 582 | |
| 583 | /* we're in trouble here, but try unwinding anyway */ |
| 584 | if (rc) { |
| 585 | printk(KERN_ERR "%s: can't create sysfs group '%s'\n", |
| 586 | __func__, attrs->name); |
| 587 | |
| 588 | list_for_each_entry_continue_reverse(spu, |
| 589 | &spu_full_list, full_list) |
| 590 | sysfs_remove_group(&spu->sysdev.kobj, attrs); |
| 591 | break; |
| 592 | } |
| 593 | } |
| 594 | |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 595 | mutex_unlock(&spu_full_list_mutex); |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 596 | |
Jeremy Kerr | 1e77103 | 2007-12-05 13:49:31 +1100 | [diff] [blame^] | 597 | return rc; |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 598 | } |
| 599 | EXPORT_SYMBOL_GPL(spu_add_sysdev_attr_group); |
| 600 | |
| 601 | |
| 602 | void spu_remove_sysdev_attr(struct sysdev_attribute *attr) |
| 603 | { |
| 604 | struct spu *spu; |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 605 | |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 606 | mutex_lock(&spu_full_list_mutex); |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 607 | list_for_each_entry(spu, &spu_full_list, full_list) |
| 608 | sysdev_remove_file(&spu->sysdev, attr); |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 609 | mutex_unlock(&spu_full_list_mutex); |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 610 | } |
| 611 | EXPORT_SYMBOL_GPL(spu_remove_sysdev_attr); |
| 612 | |
| 613 | void spu_remove_sysdev_attr_group(struct attribute_group *attrs) |
| 614 | { |
| 615 | struct spu *spu; |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 616 | |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 617 | mutex_lock(&spu_full_list_mutex); |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 618 | list_for_each_entry(spu, &spu_full_list, full_list) |
| 619 | sysfs_remove_group(&spu->sysdev.kobj, attrs); |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 620 | mutex_unlock(&spu_full_list_mutex); |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 621 | } |
| 622 | EXPORT_SYMBOL_GPL(spu_remove_sysdev_attr_group); |
| 623 | |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 624 | static int spu_create_sysdev(struct spu *spu) |
| 625 | { |
| 626 | int ret; |
| 627 | |
| 628 | spu->sysdev.id = spu->number; |
| 629 | spu->sysdev.cls = &spu_sysdev_class; |
| 630 | ret = sysdev_register(&spu->sysdev); |
| 631 | if (ret) { |
| 632 | printk(KERN_ERR "Can't register SPU %d with sysfs\n", |
| 633 | spu->number); |
| 634 | return ret; |
| 635 | } |
| 636 | |
Geoff Levand | 0021550 | 2006-11-20 18:45:02 +0100 | [diff] [blame] | 637 | sysfs_add_device_to_node(&spu->sysdev, spu->node); |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 638 | |
| 639 | return 0; |
| 640 | } |
| 641 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 642 | static int __init create_spu(void *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 643 | { |
| 644 | struct spu *spu; |
| 645 | int ret; |
| 646 | static int number; |
Benjamin Herrenschmidt | 94b2a43 | 2007-03-10 00:05:37 +0100 | [diff] [blame] | 647 | unsigned long flags; |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 648 | struct timespec ts; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 649 | |
| 650 | ret = -ENOMEM; |
Jeremy Kerr | ecec217 | 2006-06-19 20:33:26 +0200 | [diff] [blame] | 651 | spu = kzalloc(sizeof (*spu), GFP_KERNEL); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 652 | if (!spu) |
| 653 | goto out; |
| 654 | |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 655 | spu->alloc_state = SPU_FREE; |
| 656 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 657 | spin_lock_init(&spu->register_lock); |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 658 | spin_lock(&spu_lock); |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 659 | spu->number = number++; |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 660 | spin_unlock(&spu_lock); |
Benjamin Herrenschmidt | e5267b4 | 2006-10-10 15:14:12 +1000 | [diff] [blame] | 661 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 662 | ret = spu_create_spu(spu, data); |
| 663 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 664 | if (ret) |
| 665 | goto out_free; |
| 666 | |
Masato Noguchi | 24f43b3 | 2006-10-24 18:31:14 +0200 | [diff] [blame] | 667 | spu_mfc_sdr_setup(spu); |
Arnd Bergmann | f0831ac | 2006-01-04 20:31:30 +0100 | [diff] [blame] | 668 | spu_mfc_sr1_set(spu, 0x33); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 669 | ret = spu_request_irqs(spu); |
| 670 | if (ret) |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 671 | goto out_destroy; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 672 | |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 673 | ret = spu_create_sysdev(spu); |
| 674 | if (ret) |
| 675 | goto out_free_irqs; |
| 676 | |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 677 | mutex_lock(&cbe_spu_info[spu->node].list_mutex); |
Arnd Bergmann | aa6d5b2 | 2007-07-20 21:39:44 +0200 | [diff] [blame] | 678 | list_add(&spu->cbe_list, &cbe_spu_info[spu->node].spus); |
| 679 | cbe_spu_info[spu->node].n_spus++; |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 680 | mutex_unlock(&cbe_spu_info[spu->node].list_mutex); |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 681 | |
| 682 | mutex_lock(&spu_full_list_mutex); |
| 683 | spin_lock_irqsave(&spu_full_list_lock, flags); |
Christian Krafft | e570beb | 2006-10-24 18:31:23 +0200 | [diff] [blame] | 684 | list_add(&spu->full_list, &spu_full_list); |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 685 | spin_unlock_irqrestore(&spu_full_list_lock, flags); |
| 686 | mutex_unlock(&spu_full_list_mutex); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 687 | |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 688 | spu->stats.util_state = SPU_UTIL_IDLE_LOADED; |
| 689 | ktime_get_ts(&ts); |
| 690 | spu->stats.tstamp = timespec_to_ns(&ts); |
Christoph Hellwig | fe2f896 | 2007-06-29 10:58:07 +1000 | [diff] [blame] | 691 | |
Arnd Bergmann | 9d92af6 | 2007-07-20 21:39:45 +0200 | [diff] [blame] | 692 | INIT_LIST_HEAD(&spu->aff_list); |
| 693 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 694 | goto out; |
| 695 | |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 696 | out_free_irqs: |
| 697 | spu_free_irqs(spu); |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 698 | out_destroy: |
| 699 | spu_destroy_spu(spu); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 700 | out_free: |
| 701 | kfree(spu); |
| 702 | out: |
| 703 | return ret; |
| 704 | } |
| 705 | |
Christoph Hellwig | fe2f896 | 2007-06-29 10:58:07 +1000 | [diff] [blame] | 706 | static const char *spu_state_names[] = { |
| 707 | "user", "system", "iowait", "idle" |
| 708 | }; |
| 709 | |
| 710 | static unsigned long long spu_acct_time(struct spu *spu, |
| 711 | enum spu_utilization_state state) |
| 712 | { |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 713 | struct timespec ts; |
Christoph Hellwig | fe2f896 | 2007-06-29 10:58:07 +1000 | [diff] [blame] | 714 | unsigned long long time = spu->stats.times[state]; |
| 715 | |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 716 | /* |
| 717 | * If the spu is idle or the context is stopped, utilization |
| 718 | * statistics are not updated. Apply the time delta from the |
| 719 | * last recorded state of the spu. |
| 720 | */ |
| 721 | if (spu->stats.util_state == state) { |
| 722 | ktime_get_ts(&ts); |
| 723 | time += timespec_to_ns(&ts) - spu->stats.tstamp; |
| 724 | } |
Christoph Hellwig | fe2f896 | 2007-06-29 10:58:07 +1000 | [diff] [blame] | 725 | |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 726 | return time / NSEC_PER_MSEC; |
Christoph Hellwig | fe2f896 | 2007-06-29 10:58:07 +1000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
| 730 | static ssize_t spu_stat_show(struct sys_device *sysdev, char *buf) |
| 731 | { |
| 732 | struct spu *spu = container_of(sysdev, struct spu, sysdev); |
| 733 | |
| 734 | return sprintf(buf, "%s %llu %llu %llu %llu " |
| 735 | "%llu %llu %llu %llu %llu %llu %llu %llu\n", |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 736 | spu_state_names[spu->stats.util_state], |
Christoph Hellwig | fe2f896 | 2007-06-29 10:58:07 +1000 | [diff] [blame] | 737 | spu_acct_time(spu, SPU_UTIL_USER), |
| 738 | spu_acct_time(spu, SPU_UTIL_SYSTEM), |
| 739 | spu_acct_time(spu, SPU_UTIL_IOWAIT), |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 740 | spu_acct_time(spu, SPU_UTIL_IDLE_LOADED), |
Christoph Hellwig | fe2f896 | 2007-06-29 10:58:07 +1000 | [diff] [blame] | 741 | spu->stats.vol_ctx_switch, |
| 742 | spu->stats.invol_ctx_switch, |
| 743 | spu->stats.slb_flt, |
| 744 | spu->stats.hash_flt, |
| 745 | spu->stats.min_flt, |
| 746 | spu->stats.maj_flt, |
| 747 | spu->stats.class2_intr, |
| 748 | spu->stats.libassist); |
| 749 | } |
| 750 | |
| 751 | static SYSDEV_ATTR(stat, 0644, spu_stat_show, NULL); |
| 752 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 753 | static int __init init_spu_base(void) |
| 754 | { |
Christoph Hellwig | befdc74 | 2007-04-23 21:08:28 +0200 | [diff] [blame] | 755 | int i, ret = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 756 | |
Arnd Bergmann | aa6d5b2 | 2007-07-20 21:39:44 +0200 | [diff] [blame] | 757 | for (i = 0; i < MAX_NUMNODES; i++) { |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 758 | mutex_init(&cbe_spu_info[i].list_mutex); |
Arnd Bergmann | aa6d5b2 | 2007-07-20 21:39:44 +0200 | [diff] [blame] | 759 | INIT_LIST_HEAD(&cbe_spu_info[i].spus); |
Arnd Bergmann | aa6d5b2 | 2007-07-20 21:39:44 +0200 | [diff] [blame] | 760 | } |
Jeremy Kerr | ccf17e9 | 2007-04-23 21:08:29 +0200 | [diff] [blame] | 761 | |
Stephen Rothwell | da06aa0 | 2006-11-27 19:18:54 +0100 | [diff] [blame] | 762 | if (!spu_management_ops) |
Christoph Hellwig | befdc74 | 2007-04-23 21:08:28 +0200 | [diff] [blame] | 763 | goto out; |
Stephen Rothwell | da06aa0 | 2006-11-27 19:18:54 +0100 | [diff] [blame] | 764 | |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 765 | /* create sysdev class for spus */ |
| 766 | ret = sysdev_class_register(&spu_sysdev_class); |
| 767 | if (ret) |
Christoph Hellwig | befdc74 | 2007-04-23 21:08:28 +0200 | [diff] [blame] | 768 | goto out; |
Jeremy Kerr | 1d64093 | 2006-06-19 20:33:19 +0200 | [diff] [blame] | 769 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 770 | ret = spu_enumerate_spus(create_spu); |
| 771 | |
Geert Uytterhoeven | bce9451 | 2007-07-17 04:05:52 -0700 | [diff] [blame] | 772 | if (ret < 0) { |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 773 | printk(KERN_WARNING "%s: Error initializing spus\n", |
| 774 | __FUNCTION__); |
Christoph Hellwig | befdc74 | 2007-04-23 21:08:28 +0200 | [diff] [blame] | 775 | goto out_unregister_sysdev_class; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 776 | } |
Michael Ellerman | ff8a8f2 | 2006-10-24 18:31:27 +0200 | [diff] [blame] | 777 | |
Geert Uytterhoeven | bce9451 | 2007-07-17 04:05:52 -0700 | [diff] [blame] | 778 | if (ret > 0) { |
| 779 | /* |
| 780 | * We cannot put the forward declaration in |
| 781 | * <linux/linux_logo.h> because of conflicting session type |
| 782 | * conflicts for const and __initdata with different compiler |
| 783 | * versions |
| 784 | */ |
| 785 | extern const struct linux_logo logo_spe_clut224; |
| 786 | |
| 787 | fb_append_extra_logo(&logo_spe_clut224, ret); |
| 788 | } |
| 789 | |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 790 | mutex_lock(&spu_full_list_mutex); |
Michael Ellerman | ff8a8f2 | 2006-10-24 18:31:27 +0200 | [diff] [blame] | 791 | xmon_register_spus(&spu_full_list); |
Andre Detsch | 8d2655e | 2007-07-20 21:39:27 +0200 | [diff] [blame] | 792 | crash_register_spus(&spu_full_list); |
Christoph Hellwig | 2414059 | 2007-07-20 21:39:51 +0200 | [diff] [blame] | 793 | mutex_unlock(&spu_full_list_mutex); |
Christoph Hellwig | fe2f896 | 2007-06-29 10:58:07 +1000 | [diff] [blame] | 794 | spu_add_sysdev_attr(&attr_stat); |
| 795 | |
Andre Detsch | f599644 | 2007-08-03 18:53:46 -0700 | [diff] [blame] | 796 | spu_init_affinity(); |
Arnd Bergmann | 3ad216c | 2007-07-20 21:39:46 +0200 | [diff] [blame] | 797 | |
Christoph Hellwig | befdc74 | 2007-04-23 21:08:28 +0200 | [diff] [blame] | 798 | return 0; |
| 799 | |
| 800 | out_unregister_sysdev_class: |
| 801 | sysdev_class_unregister(&spu_sysdev_class); |
| 802 | out: |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 803 | return ret; |
| 804 | } |
| 805 | module_init(init_spu_base); |
| 806 | |
| 807 | MODULE_LICENSE("GPL"); |
| 808 | MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>"); |