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