📄 spu_base.c
字号:
/* * Low-level SPU handling * * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 * * Author: Arnd Bergmann <arndb@de.ibm.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#undef DEBUG#include <linux/interrupt.h>#include <linux/list.h>#include <linux/module.h>#include <linux/ptrace.h>#include <linux/slab.h>#include <linux/wait.h>#include <linux/mm.h>#include <linux/io.h>#include <linux/mutex.h>#include <linux/linux_logo.h>#include <asm/spu.h>#include <asm/spu_priv1.h>#include <asm/xmon.h>#include <asm/prom.h>const struct spu_management_ops *spu_management_ops;EXPORT_SYMBOL_GPL(spu_management_ops);const struct spu_priv1_ops *spu_priv1_ops;EXPORT_SYMBOL_GPL(spu_priv1_ops);struct cbe_spu_info cbe_spu_info[MAX_NUMNODES];EXPORT_SYMBOL_GPL(cbe_spu_info);/* * Protects cbe_spu_info and spu->number. */static DEFINE_SPINLOCK(spu_lock);/* * List of all spus in the system. * * This list is iterated by callers from irq context and callers that * want to sleep. Thus modifications need to be done with both * spu_full_list_lock and spu_full_list_mutex held, while iterating * through it requires either of these locks. * * In addition spu_full_list_lock protects all assignmens to * spu->mm. */static LIST_HEAD(spu_full_list);static DEFINE_SPINLOCK(spu_full_list_lock);static DEFINE_MUTEX(spu_full_list_mutex);void spu_invalidate_slbs(struct spu *spu){ struct spu_priv2 __iomem *priv2 = spu->priv2; if (spu_mfc_sr1_get(spu) & MFC_STATE1_RELOCATE_MASK) out_be64(&priv2->slb_invalidate_all_W, 0UL);}EXPORT_SYMBOL_GPL(spu_invalidate_slbs);/* This is called by the MM core when a segment size is changed, to * request a flush of all the SPEs using a given mm */void spu_flush_all_slbs(struct mm_struct *mm){ struct spu *spu; unsigned long flags; spin_lock_irqsave(&spu_full_list_lock, flags); list_for_each_entry(spu, &spu_full_list, full_list) { if (spu->mm == mm) spu_invalidate_slbs(spu); } spin_unlock_irqrestore(&spu_full_list_lock, flags);}/* The hack below stinks... try to do something better one of * these days... Does it even work properly with NR_CPUS == 1 ? */static inline void mm_needs_global_tlbie(struct mm_struct *mm){ int nr = (NR_CPUS > 1) ? NR_CPUS : NR_CPUS + 1; /* Global TLBIE broadcast required with SPEs. */ __cpus_setall(&mm->cpu_vm_mask, nr);}void spu_associate_mm(struct spu *spu, struct mm_struct *mm){ unsigned long flags; spin_lock_irqsave(&spu_full_list_lock, flags); spu->mm = mm; spin_unlock_irqrestore(&spu_full_list_lock, flags); if (mm) mm_needs_global_tlbie(mm);}EXPORT_SYMBOL_GPL(spu_associate_mm);static int __spu_trap_invalid_dma(struct spu *spu){ pr_debug("%s\n", __FUNCTION__); spu->dma_callback(spu, SPE_EVENT_INVALID_DMA); return 0;}static int __spu_trap_dma_align(struct spu *spu){ pr_debug("%s\n", __FUNCTION__); spu->dma_callback(spu, SPE_EVENT_DMA_ALIGNMENT); return 0;}static int __spu_trap_error(struct spu *spu){ pr_debug("%s\n", __FUNCTION__); spu->dma_callback(spu, SPE_EVENT_SPE_ERROR); return 0;}static void spu_restart_dma(struct spu *spu){ struct spu_priv2 __iomem *priv2 = spu->priv2; if (!test_bit(SPU_CONTEXT_SWITCH_PENDING, &spu->flags)) out_be64(&priv2->mfc_control_RW, MFC_CNTL_RESTART_DMA_COMMAND);}static int __spu_trap_data_seg(struct spu *spu, unsigned long ea){ struct spu_priv2 __iomem *priv2 = spu->priv2; struct mm_struct *mm = spu->mm; u64 esid, vsid, llp; int psize; pr_debug("%s\n", __FUNCTION__); if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) { /* SLBs are pre-loaded for context switch, so * we should never get here! */ printk("%s: invalid access during switch!\n", __func__); return 1; } esid = (ea & ESID_MASK) | SLB_ESID_V; switch(REGION_ID(ea)) { case USER_REGION_ID:#ifdef CONFIG_PPC_MM_SLICES psize = get_slice_psize(mm, ea);#else psize = mm->context.user_psize;#endif vsid = (get_vsid(mm->context.id, ea, MMU_SEGSIZE_256M) << SLB_VSID_SHIFT) | SLB_VSID_USER; break; case VMALLOC_REGION_ID: if (ea < VMALLOC_END) psize = mmu_vmalloc_psize; else psize = mmu_io_psize; vsid = (get_kernel_vsid(ea, MMU_SEGSIZE_256M) << SLB_VSID_SHIFT) | SLB_VSID_KERNEL; break; case KERNEL_REGION_ID: psize = mmu_linear_psize; vsid = (get_kernel_vsid(ea, MMU_SEGSIZE_256M) << SLB_VSID_SHIFT) | SLB_VSID_KERNEL; break; default: /* Future: support kernel segments so that drivers * can use SPUs. */ pr_debug("invalid region access at %016lx\n", ea); return 1; } llp = mmu_psize_defs[psize].sllp; out_be64(&priv2->slb_index_W, spu->slb_replace); out_be64(&priv2->slb_vsid_RW, vsid | llp); out_be64(&priv2->slb_esid_RW, esid); spu->slb_replace++; if (spu->slb_replace >= 8) spu->slb_replace = 0; spu_restart_dma(spu); spu->stats.slb_flt++; return 0;}extern int hash_page(unsigned long ea, unsigned long access, unsigned long trap); //XXXstatic int __spu_trap_data_map(struct spu *spu, unsigned long ea, u64 dsisr){ pr_debug("%s, %lx, %lx\n", __FUNCTION__, dsisr, ea); /* Handle kernel space hash faults immediately. User hash faults need to be deferred to process context. */ if ((dsisr & MFC_DSISR_PTE_NOT_FOUND) && REGION_ID(ea) != USER_REGION_ID && hash_page(ea, _PAGE_PRESENT, 0x300) == 0) { spu_restart_dma(spu); return 0; } if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) { printk("%s: invalid access during switch!\n", __func__); return 1; } spu->dar = ea; spu->dsisr = dsisr; mb(); spu->stop_callback(spu); return 0;}static irqreturn_tspu_irq_class_0(int irq, void *data){ struct spu *spu; unsigned long stat, mask; spu = data; mask = spu_int_mask_get(spu, 0); stat = spu_int_stat_get(spu, 0); stat &= mask; spin_lock(&spu->register_lock); spu->class_0_pending |= stat; spin_unlock(&spu->register_lock); spu->stop_callback(spu); spu_int_stat_clear(spu, 0, stat); return IRQ_HANDLED;}intspu_irq_class_0_bottom(struct spu *spu){ unsigned long flags; unsigned long stat; spin_lock_irqsave(&spu->register_lock, flags); stat = spu->class_0_pending; spu->class_0_pending = 0; if (stat & 1) /* invalid DMA alignment */ __spu_trap_dma_align(spu); if (stat & 2) /* invalid MFC DMA */ __spu_trap_invalid_dma(spu); if (stat & 4) /* error on SPU */ __spu_trap_error(spu); spin_unlock_irqrestore(&spu->register_lock, flags); return (stat & 0x7) ? -EIO : 0;}EXPORT_SYMBOL_GPL(spu_irq_class_0_bottom);static irqreturn_tspu_irq_class_1(int irq, void *data){ struct spu *spu; unsigned long stat, mask, dar, dsisr; spu = data; /* atomically read & clear class1 status. */ spin_lock(&spu->register_lock); mask = spu_int_mask_get(spu, 1); stat = spu_int_stat_get(spu, 1) & mask; dar = spu_mfc_dar_get(spu); dsisr = spu_mfc_dsisr_get(spu); if (stat & 2) /* mapping fault */ spu_mfc_dsisr_set(spu, 0ul); spu_int_stat_clear(spu, 1, stat); spin_unlock(&spu->register_lock); pr_debug("%s: %lx %lx %lx %lx\n", __FUNCTION__, mask, stat, dar, dsisr); if (stat & 1) /* segment fault */ __spu_trap_data_seg(spu, dar); if (stat & 2) { /* mapping fault */ __spu_trap_data_map(spu, dar, dsisr); } if (stat & 4) /* ls compare & suspend on get */ ; if (stat & 8) /* ls compare & suspend on put */ ; return stat ? IRQ_HANDLED : IRQ_NONE;}static irqreturn_tspu_irq_class_2(int irq, void *data){ struct spu *spu; unsigned long stat; unsigned long mask; spu = data; spin_lock(&spu->register_lock); stat = spu_int_stat_get(spu, 2); mask = spu_int_mask_get(spu, 2); /* ignore interrupts we're not waiting for */ stat &= mask; /* * mailbox interrupts (0x1 and 0x10) are level triggered. * mask them now before acknowledging. */ if (stat & 0x11) spu_int_mask_and(spu, 2, ~(stat & 0x11)); /* acknowledge all interrupts before the callbacks */ spu_int_stat_clear(spu, 2, stat); spin_unlock(&spu->register_lock); pr_debug("class 2 interrupt %d, %lx, %lx\n", irq, stat, mask); if (stat & 1) /* PPC core mailbox */ spu->ibox_callback(spu); if (stat & 2) /* SPU stop-and-signal */ spu->stop_callback(spu);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -