2005-11-16 04:53:48 +08:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2005-12-06 11:52:24 +08:00
|
|
|
#undef DEBUG
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/wait.h>
|
2006-11-23 07:46:49 +08:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/io.h>
|
2006-03-26 17:37:14 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-11-16 04:53:48 +08:00
|
|
|
#include <asm/spu.h>
|
2006-06-20 02:33:29 +08:00
|
|
|
#include <asm/spu_priv1.h>
|
2006-10-25 00:31:27 +08:00
|
|
|
#include <asm/xmon.h>
|
2005-11-16 04:53:48 +08:00
|
|
|
|
2006-11-23 07:46:49 +08:00
|
|
|
const struct spu_management_ops *spu_management_ops;
|
2006-06-20 02:33:29 +08:00
|
|
|
const struct spu_priv1_ops *spu_priv1_ops;
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(spu_priv1_ops);
|
|
|
|
|
2005-11-16 04:53:48 +08:00
|
|
|
static int __spu_trap_invalid_dma(struct spu *spu)
|
|
|
|
{
|
|
|
|
pr_debug("%s\n", __FUNCTION__);
|
2006-10-04 23:26:14 +08:00
|
|
|
spu->dma_callback(spu, SPE_EVENT_INVALID_DMA);
|
2005-11-16 04:53:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __spu_trap_dma_align(struct spu *spu)
|
|
|
|
{
|
|
|
|
pr_debug("%s\n", __FUNCTION__);
|
2006-10-04 23:26:14 +08:00
|
|
|
spu->dma_callback(spu, SPE_EVENT_DMA_ALIGNMENT);
|
2005-11-16 04:53:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __spu_trap_error(struct spu *spu)
|
|
|
|
{
|
|
|
|
pr_debug("%s\n", __FUNCTION__);
|
2006-10-04 23:26:14 +08:00
|
|
|
spu->dma_callback(spu, SPE_EVENT_SPE_ERROR);
|
2005-11-16 04:53:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void spu_restart_dma(struct spu *spu)
|
|
|
|
{
|
|
|
|
struct spu_priv2 __iomem *priv2 = spu->priv2;
|
2005-11-16 04:53:49 +08:00
|
|
|
|
2006-01-05 03:31:28 +08:00
|
|
|
if (!test_bit(SPU_CONTEXT_SWITCH_PENDING, &spu->flags))
|
2005-11-16 04:53:49 +08:00
|
|
|
out_be64(&priv2->mfc_control_RW, MFC_CNTL_RESTART_DMA_COMMAND);
|
2005-11-16 04:53:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __spu_trap_data_seg(struct spu *spu, unsigned long ea)
|
|
|
|
{
|
2005-11-16 04:53:52 +08:00
|
|
|
struct spu_priv2 __iomem *priv2 = spu->priv2;
|
|
|
|
struct mm_struct *mm = spu->mm;
|
2006-06-20 02:33:23 +08:00
|
|
|
u64 esid, vsid, llp;
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
pr_debug("%s\n", __FUNCTION__);
|
|
|
|
|
2006-01-05 03:31:28 +08:00
|
|
|
if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) {
|
2005-11-16 04:53:52 +08:00
|
|
|
/* SLBs are pre-loaded for context switch, so
|
|
|
|
* we should never get here!
|
|
|
|
*/
|
2005-11-16 04:53:49 +08:00
|
|
|
printk("%s: invalid access during switch!\n", __func__);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-10-25 00:31:18 +08:00
|
|
|
esid = (ea & ESID_MASK) | SLB_ESID_V;
|
|
|
|
|
|
|
|
switch(REGION_ID(ea)) {
|
|
|
|
case USER_REGION_ID:
|
|
|
|
#ifdef CONFIG_HUGETLB_PAGE
|
|
|
|
if (in_hugepage_area(mm->context, ea))
|
|
|
|
llp = mmu_psize_defs[mmu_huge_psize].sllp;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
llp = mmu_psize_defs[mmu_virtual_psize].sllp;
|
|
|
|
vsid = (get_vsid(mm->context.id, ea) << SLB_VSID_SHIFT) |
|
|
|
|
SLB_VSID_USER | llp;
|
|
|
|
break;
|
|
|
|
case VMALLOC_REGION_ID:
|
|
|
|
llp = mmu_psize_defs[mmu_virtual_psize].sllp;
|
|
|
|
vsid = (get_kernel_vsid(ea) << SLB_VSID_SHIFT) |
|
|
|
|
SLB_VSID_KERNEL | llp;
|
|
|
|
break;
|
|
|
|
case KERNEL_REGION_ID:
|
|
|
|
llp = mmu_psize_defs[mmu_linear_psize].sllp;
|
|
|
|
vsid = (get_kernel_vsid(ea) << SLB_VSID_SHIFT) |
|
|
|
|
SLB_VSID_KERNEL | llp;
|
|
|
|
break;
|
|
|
|
default:
|
2005-11-16 04:53:52 +08:00
|
|
|
/* Future: support kernel segments so that drivers
|
|
|
|
* can use SPUs.
|
|
|
|
*/
|
2005-11-16 04:53:48 +08:00
|
|
|
pr_debug("invalid region access at %016lx\n", ea);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-11-16 04:53:52 +08:00
|
|
|
out_be64(&priv2->slb_index_W, spu->slb_replace);
|
|
|
|
out_be64(&priv2->slb_vsid_RW, vsid);
|
|
|
|
out_be64(&priv2->slb_esid_RW, esid);
|
|
|
|
|
|
|
|
spu->slb_replace++;
|
2005-11-16 04:53:48 +08:00
|
|
|
if (spu->slb_replace >= 8)
|
|
|
|
spu->slb_replace = 0;
|
|
|
|
|
|
|
|
spu_restart_dma(spu);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-16 04:53:49 +08:00
|
|
|
extern int hash_page(unsigned long ea, unsigned long access, unsigned long trap); //XXX
|
2005-11-16 04:53:52 +08:00
|
|
|
static int __spu_trap_data_map(struct spu *spu, unsigned long ea, u64 dsisr)
|
2005-11-16 04:53:48 +08:00
|
|
|
{
|
2006-03-23 07:00:11 +08:00
|
|
|
pr_debug("%s, %lx, %lx\n", __FUNCTION__, dsisr, ea);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
2005-11-16 04:53:49 +08:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2006-01-05 03:31:28 +08:00
|
|
|
if (test_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags)) {
|
2005-11-16 04:53:49 +08:00
|
|
|
printk("%s: invalid access during switch!\n", __func__);
|
|
|
|
return 1;
|
|
|
|
}
|
2005-11-16 04:53:48 +08:00
|
|
|
|
2005-11-16 04:53:52 +08:00
|
|
|
spu->dar = ea;
|
|
|
|
spu->dsisr = dsisr;
|
|
|
|
mb();
|
2006-06-20 02:33:33 +08:00
|
|
|
spu->stop_callback(spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t
|
2006-10-07 04:52:16 +08:00
|
|
|
spu_irq_class_0(int irq, void *data)
|
2005-11-16 04:53:48 +08:00
|
|
|
{
|
|
|
|
struct spu *spu;
|
|
|
|
|
|
|
|
spu = data;
|
|
|
|
spu->class_0_pending = 1;
|
2006-06-20 02:33:33 +08:00
|
|
|
spu->stop_callback(spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2005-12-06 11:52:25 +08:00
|
|
|
int
|
2005-11-16 04:53:48 +08:00
|
|
|
spu_irq_class_0_bottom(struct spu *spu)
|
|
|
|
{
|
2005-12-06 11:52:27 +08:00
|
|
|
unsigned long stat, mask;
|
2007-01-12 08:52:41 +08:00
|
|
|
unsigned long flags;
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
spu->class_0_pending = 0;
|
|
|
|
|
2007-01-12 08:52:41 +08:00
|
|
|
spin_lock_irqsave(&spu->register_lock, flags);
|
2006-01-05 03:31:30 +08:00
|
|
|
mask = spu_int_mask_get(spu, 0);
|
|
|
|
stat = spu_int_stat_get(spu, 0);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
2005-12-06 11:52:27 +08:00
|
|
|
stat &= mask;
|
|
|
|
|
2006-06-24 02:57:50 +08:00
|
|
|
if (stat & 1) /* invalid DMA alignment */
|
2005-11-16 04:53:48 +08:00
|
|
|
__spu_trap_dma_align(spu);
|
|
|
|
|
2006-06-24 02:57:50 +08:00
|
|
|
if (stat & 2) /* invalid MFC DMA */
|
|
|
|
__spu_trap_invalid_dma(spu);
|
|
|
|
|
2005-11-16 04:53:48 +08:00
|
|
|
if (stat & 4) /* error on SPU */
|
|
|
|
__spu_trap_error(spu);
|
|
|
|
|
2006-01-05 03:31:30 +08:00
|
|
|
spu_int_stat_clear(spu, 0, stat);
|
2007-01-12 08:52:41 +08:00
|
|
|
spin_unlock_irqrestore(&spu->register_lock, flags);
|
2005-12-06 11:52:25 +08:00
|
|
|
|
|
|
|
return (stat & 0x7) ? -EIO : 0;
|
2005-11-16 04:53:48 +08:00
|
|
|
}
|
2005-12-06 11:52:25 +08:00
|
|
|
EXPORT_SYMBOL_GPL(spu_irq_class_0_bottom);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
static irqreturn_t
|
2006-10-07 04:52:16 +08:00
|
|
|
spu_irq_class_1(int irq, void *data)
|
2005-11-16 04:53:48 +08:00
|
|
|
{
|
|
|
|
struct spu *spu;
|
2005-11-16 04:53:52 +08:00
|
|
|
unsigned long stat, mask, dar, dsisr;
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
spu = data;
|
2005-11-16 04:53:52 +08:00
|
|
|
|
|
|
|
/* atomically read & clear class1 status. */
|
|
|
|
spin_lock(&spu->register_lock);
|
2006-01-05 03:31:30 +08:00
|
|
|
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);
|
2005-12-10 02:04:18 +08:00
|
|
|
if (stat & 2) /* mapping fault */
|
2006-01-05 03:31:30 +08:00
|
|
|
spu_mfc_dsisr_set(spu, 0ul);
|
|
|
|
spu_int_stat_clear(spu, 1, stat);
|
2005-11-16 04:53:52 +08:00
|
|
|
spin_unlock(&spu->register_lock);
|
2006-03-23 07:00:11 +08:00
|
|
|
pr_debug("%s: %lx %lx %lx %lx\n", __FUNCTION__, mask, stat,
|
|
|
|
dar, dsisr);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
if (stat & 1) /* segment fault */
|
|
|
|
__spu_trap_data_seg(spu, dar);
|
|
|
|
|
|
|
|
if (stat & 2) { /* mapping fault */
|
2005-11-16 04:53:52 +08:00
|
|
|
__spu_trap_data_map(spu, dar, dsisr);
|
2005-11-16 04:53:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stat & 4) /* ls compare & suspend on get */
|
|
|
|
;
|
|
|
|
|
|
|
|
if (stat & 8) /* ls compare & suspend on put */
|
|
|
|
;
|
|
|
|
|
|
|
|
return stat ? IRQ_HANDLED : IRQ_NONE;
|
|
|
|
}
|
2005-12-06 11:52:25 +08:00
|
|
|
EXPORT_SYMBOL_GPL(spu_irq_class_1_bottom);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
static irqreturn_t
|
2006-10-07 04:52:16 +08:00
|
|
|
spu_irq_class_2(int irq, void *data)
|
2005-11-16 04:53:48 +08:00
|
|
|
{
|
|
|
|
struct spu *spu;
|
|
|
|
unsigned long stat;
|
2005-12-06 11:52:27 +08:00
|
|
|
unsigned long mask;
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
spu = data;
|
2006-06-20 02:33:33 +08:00
|
|
|
spin_lock(&spu->register_lock);
|
2006-01-05 03:31:30 +08:00
|
|
|
stat = spu_int_stat_get(spu, 2);
|
|
|
|
mask = spu_int_mask_get(spu, 2);
|
2006-06-20 02:33:33 +08:00
|
|
|
/* 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);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
2005-12-06 11:52:27 +08:00
|
|
|
pr_debug("class 2 interrupt %d, %lx, %lx\n", irq, stat, mask);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
if (stat & 1) /* PPC core mailbox */
|
2006-06-20 02:33:33 +08:00
|
|
|
spu->ibox_callback(spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
if (stat & 2) /* SPU stop-and-signal */
|
2006-06-20 02:33:33 +08:00
|
|
|
spu->stop_callback(spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
if (stat & 4) /* SPU halted */
|
2006-06-20 02:33:33 +08:00
|
|
|
spu->stop_callback(spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
if (stat & 8) /* DMA tag group complete */
|
2006-06-20 02:33:33 +08:00
|
|
|
spu->mfc_callback(spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
if (stat & 0x10) /* SPU mailbox threshold */
|
2006-06-20 02:33:33 +08:00
|
|
|
spu->wbox_callback(spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
return stat ? IRQ_HANDLED : IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
2006-07-03 19:36:01 +08:00
|
|
|
static int spu_request_irqs(struct spu *spu)
|
2005-11-16 04:53:48 +08:00
|
|
|
{
|
2006-07-03 19:36:01 +08:00
|
|
|
int ret = 0;
|
2005-11-16 04:53:48 +08:00
|
|
|
|
2006-07-03 19:36:01 +08:00
|
|
|
if (spu->irqs[0] != NO_IRQ) {
|
|
|
|
snprintf(spu->irq_c0, sizeof (spu->irq_c0), "spe%02d.0",
|
|
|
|
spu->number);
|
|
|
|
ret = request_irq(spu->irqs[0], spu_irq_class_0,
|
|
|
|
IRQF_DISABLED,
|
|
|
|
spu->irq_c0, spu);
|
|
|
|
if (ret)
|
|
|
|
goto bail0;
|
|
|
|
}
|
|
|
|
if (spu->irqs[1] != NO_IRQ) {
|
|
|
|
snprintf(spu->irq_c1, sizeof (spu->irq_c1), "spe%02d.1",
|
|
|
|
spu->number);
|
|
|
|
ret = request_irq(spu->irqs[1], spu_irq_class_1,
|
|
|
|
IRQF_DISABLED,
|
|
|
|
spu->irq_c1, spu);
|
|
|
|
if (ret)
|
|
|
|
goto bail1;
|
|
|
|
}
|
|
|
|
if (spu->irqs[2] != NO_IRQ) {
|
|
|
|
snprintf(spu->irq_c2, sizeof (spu->irq_c2), "spe%02d.2",
|
|
|
|
spu->number);
|
|
|
|
ret = request_irq(spu->irqs[2], spu_irq_class_2,
|
|
|
|
IRQF_DISABLED,
|
|
|
|
spu->irq_c2, spu);
|
|
|
|
if (ret)
|
|
|
|
goto bail2;
|
|
|
|
}
|
|
|
|
return 0;
|
2005-11-16 04:53:48 +08:00
|
|
|
|
2006-07-03 19:36:01 +08:00
|
|
|
bail2:
|
|
|
|
if (spu->irqs[1] != NO_IRQ)
|
|
|
|
free_irq(spu->irqs[1], spu);
|
|
|
|
bail1:
|
|
|
|
if (spu->irqs[0] != NO_IRQ)
|
|
|
|
free_irq(spu->irqs[0], spu);
|
|
|
|
bail0:
|
2005-11-16 04:53:48 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-03 19:36:01 +08:00
|
|
|
static void spu_free_irqs(struct spu *spu)
|
2005-11-16 04:53:48 +08:00
|
|
|
{
|
2006-07-03 19:36:01 +08:00
|
|
|
if (spu->irqs[0] != NO_IRQ)
|
|
|
|
free_irq(spu->irqs[0], spu);
|
|
|
|
if (spu->irqs[1] != NO_IRQ)
|
|
|
|
free_irq(spu->irqs[1], spu);
|
|
|
|
if (spu->irqs[2] != NO_IRQ)
|
|
|
|
free_irq(spu->irqs[2], spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
}
|
|
|
|
|
2006-10-04 23:26:12 +08:00
|
|
|
static struct list_head spu_list[MAX_NUMNODES];
|
2006-10-25 00:31:23 +08:00
|
|
|
static LIST_HEAD(spu_full_list);
|
2006-03-26 17:37:14 +08:00
|
|
|
static DEFINE_MUTEX(spu_mutex);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
static void spu_init_channels(struct spu *spu)
|
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
unsigned channel;
|
|
|
|
unsigned count;
|
|
|
|
} zero_list[] = {
|
|
|
|
{ 0x00, 1, }, { 0x01, 1, }, { 0x03, 1, }, { 0x04, 1, },
|
|
|
|
{ 0x18, 1, }, { 0x19, 1, }, { 0x1b, 1, }, { 0x1d, 1, },
|
|
|
|
}, count_list[] = {
|
|
|
|
{ 0x00, 0, }, { 0x03, 0, }, { 0x04, 0, }, { 0x15, 16, },
|
|
|
|
{ 0x17, 1, }, { 0x18, 0, }, { 0x19, 0, }, { 0x1b, 0, },
|
|
|
|
{ 0x1c, 1, }, { 0x1d, 0, }, { 0x1e, 1, },
|
|
|
|
};
|
2006-01-05 03:31:31 +08:00
|
|
|
struct spu_priv2 __iomem *priv2;
|
2005-11-16 04:53:48 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
priv2 = spu->priv2;
|
|
|
|
|
|
|
|
/* initialize all channel data to zero */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(zero_list); i++) {
|
|
|
|
int count;
|
|
|
|
|
|
|
|
out_be64(&priv2->spu_chnlcntptr_RW, zero_list[i].channel);
|
|
|
|
for (count = 0; count < zero_list[i].count; count++)
|
|
|
|
out_be64(&priv2->spu_chnldata_RW, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize channel counts to meaningful values */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(count_list); i++) {
|
|
|
|
out_be64(&priv2->spu_chnlcntptr_RW, count_list[i].channel);
|
|
|
|
out_be64(&priv2->spu_chnlcnt_RW, count_list[i].count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-04 23:26:12 +08:00
|
|
|
struct spu *spu_alloc_node(int node)
|
2005-11-16 04:53:48 +08:00
|
|
|
{
|
2006-10-04 23:26:12 +08:00
|
|
|
struct spu *spu = NULL;
|
2005-11-16 04:53:48 +08:00
|
|
|
|
2006-03-26 17:37:14 +08:00
|
|
|
mutex_lock(&spu_mutex);
|
2006-10-04 23:26:12 +08:00
|
|
|
if (!list_empty(&spu_list[node])) {
|
|
|
|
spu = list_entry(spu_list[node].next, struct spu, list);
|
2005-11-16 04:53:48 +08:00
|
|
|
list_del_init(&spu->list);
|
2006-10-25 00:31:15 +08:00
|
|
|
pr_debug("Got SPU %d %d\n", spu->number, spu->node);
|
2006-10-04 23:26:12 +08:00
|
|
|
spu_init_channels(spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
}
|
2006-03-26 17:37:14 +08:00
|
|
|
mutex_unlock(&spu_mutex);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
2006-10-04 23:26:12 +08:00
|
|
|
return spu;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(spu_alloc_node);
|
|
|
|
|
|
|
|
struct spu *spu_alloc(void)
|
|
|
|
{
|
|
|
|
struct spu *spu = NULL;
|
|
|
|
int node;
|
|
|
|
|
|
|
|
for (node = 0; node < MAX_NUMNODES; node++) {
|
|
|
|
spu = spu_alloc_node(node);
|
|
|
|
if (spu)
|
|
|
|
break;
|
|
|
|
}
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
return spu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void spu_free(struct spu *spu)
|
|
|
|
{
|
2006-03-26 17:37:14 +08:00
|
|
|
mutex_lock(&spu_mutex);
|
2006-10-04 23:26:12 +08:00
|
|
|
list_add_tail(&spu->list, &spu_list[spu->node]);
|
2006-03-26 17:37:14 +08:00
|
|
|
mutex_unlock(&spu_mutex);
|
2005-11-16 04:53:48 +08:00
|
|
|
}
|
2005-12-06 11:52:21 +08:00
|
|
|
EXPORT_SYMBOL_GPL(spu_free);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
static int spu_handle_mm_fault(struct spu *spu)
|
|
|
|
{
|
|
|
|
struct mm_struct *mm = spu->mm;
|
|
|
|
struct vm_area_struct *vma;
|
|
|
|
u64 ea, dsisr, is_write;
|
|
|
|
int ret;
|
|
|
|
|
2005-11-16 04:53:52 +08:00
|
|
|
ea = spu->dar;
|
|
|
|
dsisr = spu->dsisr;
|
2005-11-16 04:53:48 +08:00
|
|
|
#if 0
|
|
|
|
if (!IS_VALID_EA(ea)) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
#endif /* XXX */
|
|
|
|
if (mm == NULL) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
if (mm->pgd == NULL) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
down_read(&mm->mmap_sem);
|
|
|
|
vma = find_vma(mm, ea);
|
|
|
|
if (!vma)
|
|
|
|
goto bad_area;
|
|
|
|
if (vma->vm_start <= ea)
|
|
|
|
goto good_area;
|
|
|
|
if (!(vma->vm_flags & VM_GROWSDOWN))
|
|
|
|
goto bad_area;
|
|
|
|
#if 0
|
|
|
|
if (expand_stack(vma, ea))
|
|
|
|
goto bad_area;
|
|
|
|
#endif /* XXX */
|
|
|
|
good_area:
|
|
|
|
is_write = dsisr & MFC_DSISR_ACCESS_PUT;
|
|
|
|
if (is_write) {
|
|
|
|
if (!(vma->vm_flags & VM_WRITE))
|
|
|
|
goto bad_area;
|
|
|
|
} else {
|
|
|
|
if (dsisr & MFC_DSISR_ACCESS_DENIED)
|
|
|
|
goto bad_area;
|
|
|
|
if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
|
|
|
|
goto bad_area;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
switch (handle_mm_fault(mm, vma, ea, is_write)) {
|
|
|
|
case VM_FAULT_MINOR:
|
|
|
|
current->min_flt++;
|
|
|
|
break;
|
|
|
|
case VM_FAULT_MAJOR:
|
|
|
|
current->maj_flt++;
|
|
|
|
break;
|
|
|
|
case VM_FAULT_SIGBUS:
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto bad_area;
|
|
|
|
case VM_FAULT_OOM:
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto bad_area;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
up_read(&mm->mmap_sem);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
bad_area:
|
|
|
|
up_read(&mm->mmap_sem);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2005-12-06 11:52:25 +08:00
|
|
|
int spu_irq_class_1_bottom(struct spu *spu)
|
2005-11-16 04:53:48 +08:00
|
|
|
{
|
|
|
|
u64 ea, dsisr, access, error = 0UL;
|
|
|
|
int ret = 0;
|
|
|
|
|
2005-11-16 04:53:52 +08:00
|
|
|
ea = spu->dar;
|
|
|
|
dsisr = spu->dsisr;
|
2006-03-25 02:49:27 +08:00
|
|
|
if (dsisr & (MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED)) {
|
2006-04-29 08:40:21 +08:00
|
|
|
u64 flags;
|
|
|
|
|
2005-11-16 04:53:52 +08:00
|
|
|
access = (_PAGE_PRESENT | _PAGE_USER);
|
|
|
|
access |= (dsisr & MFC_DSISR_ACCESS_PUT) ? _PAGE_RW : 0UL;
|
2006-04-29 08:40:21 +08:00
|
|
|
local_irq_save(flags);
|
2005-11-16 04:53:48 +08:00
|
|
|
if (hash_page(ea, access, 0x300) != 0)
|
|
|
|
error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
|
2006-04-29 08:40:21 +08:00
|
|
|
local_irq_restore(flags);
|
2005-11-16 04:53:48 +08:00
|
|
|
}
|
2006-03-25 02:49:27 +08:00
|
|
|
if (error & CLASS1_ENABLE_STORAGE_FAULT_INTR) {
|
2005-11-16 04:53:48 +08:00
|
|
|
if ((ret = spu_handle_mm_fault(spu)) != 0)
|
|
|
|
error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
|
|
|
|
else
|
|
|
|
error &= ~CLASS1_ENABLE_STORAGE_FAULT_INTR;
|
|
|
|
}
|
2005-11-16 04:53:52 +08:00
|
|
|
spu->dar = 0UL;
|
|
|
|
spu->dsisr = 0UL;
|
|
|
|
if (!error) {
|
2005-11-16 04:53:48 +08:00
|
|
|
spu_restart_dma(spu);
|
2005-11-16 04:53:52 +08:00
|
|
|
} else {
|
2006-11-21 01:45:03 +08:00
|
|
|
spu->dma_callback(spu, SPE_EVENT_SPE_DATA_STORAGE);
|
2005-11-16 04:53:52 +08:00
|
|
|
}
|
2005-11-16 04:53:48 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-06-20 02:33:19 +08:00
|
|
|
struct sysdev_class spu_sysdev_class = {
|
|
|
|
set_kset_name("spu")
|
|
|
|
};
|
|
|
|
|
2006-10-25 00:31:23 +08:00
|
|
|
int spu_add_sysdev_attr(struct sysdev_attribute *attr)
|
|
|
|
{
|
|
|
|
struct spu *spu;
|
|
|
|
mutex_lock(&spu_mutex);
|
|
|
|
|
|
|
|
list_for_each_entry(spu, &spu_full_list, full_list)
|
|
|
|
sysdev_create_file(&spu->sysdev, attr);
|
|
|
|
|
|
|
|
mutex_unlock(&spu_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(spu_add_sysdev_attr);
|
|
|
|
|
|
|
|
int spu_add_sysdev_attr_group(struct attribute_group *attrs)
|
|
|
|
{
|
|
|
|
struct spu *spu;
|
|
|
|
mutex_lock(&spu_mutex);
|
|
|
|
|
|
|
|
list_for_each_entry(spu, &spu_full_list, full_list)
|
|
|
|
sysfs_create_group(&spu->sysdev.kobj, attrs);
|
|
|
|
|
|
|
|
mutex_unlock(&spu_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(spu_add_sysdev_attr_group);
|
|
|
|
|
|
|
|
|
|
|
|
void spu_remove_sysdev_attr(struct sysdev_attribute *attr)
|
|
|
|
{
|
|
|
|
struct spu *spu;
|
|
|
|
mutex_lock(&spu_mutex);
|
|
|
|
|
|
|
|
list_for_each_entry(spu, &spu_full_list, full_list)
|
|
|
|
sysdev_remove_file(&spu->sysdev, attr);
|
|
|
|
|
|
|
|
mutex_unlock(&spu_mutex);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(spu_remove_sysdev_attr);
|
|
|
|
|
|
|
|
void spu_remove_sysdev_attr_group(struct attribute_group *attrs)
|
|
|
|
{
|
|
|
|
struct spu *spu;
|
|
|
|
mutex_lock(&spu_mutex);
|
|
|
|
|
|
|
|
list_for_each_entry(spu, &spu_full_list, full_list)
|
|
|
|
sysfs_remove_group(&spu->sysdev.kobj, attrs);
|
|
|
|
|
|
|
|
mutex_unlock(&spu_mutex);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(spu_remove_sysdev_attr_group);
|
|
|
|
|
2006-06-20 02:33:19 +08:00
|
|
|
static int spu_create_sysdev(struct spu *spu)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
spu->sysdev.id = spu->number;
|
|
|
|
spu->sysdev.cls = &spu_sysdev_class;
|
|
|
|
ret = sysdev_register(&spu->sysdev);
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_ERR "Can't register SPU %d with sysfs\n",
|
|
|
|
spu->number);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-11-21 01:45:02 +08:00
|
|
|
sysfs_add_device_to_node(&spu->sysdev, spu->node);
|
2006-06-20 02:33:19 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void spu_destroy_sysdev(struct spu *spu)
|
|
|
|
{
|
2006-11-21 01:45:02 +08:00
|
|
|
sysfs_remove_device_from_node(&spu->sysdev, spu->node);
|
2006-06-20 02:33:19 +08:00
|
|
|
sysdev_unregister(&spu->sysdev);
|
|
|
|
}
|
|
|
|
|
2006-11-23 07:46:49 +08:00
|
|
|
static int __init create_spu(void *data)
|
2005-11-16 04:53:48 +08:00
|
|
|
{
|
|
|
|
struct spu *spu;
|
|
|
|
int ret;
|
|
|
|
static int number;
|
|
|
|
|
|
|
|
ret = -ENOMEM;
|
2006-06-20 02:33:26 +08:00
|
|
|
spu = kzalloc(sizeof (*spu), GFP_KERNEL);
|
2005-11-16 04:53:48 +08:00
|
|
|
if (!spu)
|
|
|
|
goto out;
|
|
|
|
|
2006-11-23 07:46:49 +08:00
|
|
|
spin_lock_init(&spu->register_lock);
|
|
|
|
mutex_lock(&spu_mutex);
|
|
|
|
spu->number = number++;
|
|
|
|
mutex_unlock(&spu_mutex);
|
|
|
|
|
|
|
|
ret = spu_create_spu(spu, data);
|
2006-10-10 13:14:12 +08:00
|
|
|
|
2005-11-16 04:53:48 +08:00
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
|
|
|
|
2006-10-25 00:31:14 +08:00
|
|
|
spu_mfc_sdr_setup(spu);
|
2006-01-05 03:31:30 +08:00
|
|
|
spu_mfc_sr1_set(spu, 0x33);
|
2005-11-16 04:53:48 +08:00
|
|
|
ret = spu_request_irqs(spu);
|
|
|
|
if (ret)
|
2006-11-23 07:46:49 +08:00
|
|
|
goto out_destroy;
|
2005-11-16 04:53:48 +08:00
|
|
|
|
2006-06-20 02:33:19 +08:00
|
|
|
ret = spu_create_sysdev(spu);
|
|
|
|
if (ret)
|
|
|
|
goto out_free_irqs;
|
|
|
|
|
2006-11-23 07:46:49 +08:00
|
|
|
mutex_lock(&spu_mutex);
|
2006-10-04 23:26:12 +08:00
|
|
|
list_add(&spu->list, &spu_list[spu->node]);
|
2006-10-25 00:31:23 +08:00
|
|
|
list_add(&spu->full_list, &spu_full_list);
|
2006-03-26 17:37:14 +08:00
|
|
|
mutex_unlock(&spu_mutex);
|
2005-11-16 04:53:48 +08:00
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
2006-06-20 02:33:19 +08:00
|
|
|
out_free_irqs:
|
|
|
|
spu_free_irqs(spu);
|
2006-11-23 07:46:49 +08:00
|
|
|
out_destroy:
|
|
|
|
spu_destroy_spu(spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
out_free:
|
|
|
|
kfree(spu);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_spu(struct spu *spu)
|
|
|
|
{
|
|
|
|
list_del_init(&spu->list);
|
2006-10-25 00:31:23 +08:00
|
|
|
list_del_init(&spu->full_list);
|
|
|
|
|
2006-06-20 02:33:19 +08:00
|
|
|
spu_destroy_sysdev(spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
spu_free_irqs(spu);
|
2006-11-23 07:46:49 +08:00
|
|
|
spu_destroy_spu(spu);
|
2005-11-16 04:53:48 +08:00
|
|
|
kfree(spu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cleanup_spu_base(void)
|
|
|
|
{
|
|
|
|
struct spu *spu, *tmp;
|
2006-10-04 23:26:12 +08:00
|
|
|
int node;
|
|
|
|
|
2006-03-26 17:37:14 +08:00
|
|
|
mutex_lock(&spu_mutex);
|
2006-10-04 23:26:12 +08:00
|
|
|
for (node = 0; node < MAX_NUMNODES; node++) {
|
|
|
|
list_for_each_entry_safe(spu, tmp, &spu_list[node], list)
|
|
|
|
destroy_spu(spu);
|
|
|
|
}
|
2006-03-26 17:37:14 +08:00
|
|
|
mutex_unlock(&spu_mutex);
|
2006-06-20 02:33:19 +08:00
|
|
|
sysdev_class_unregister(&spu_sysdev_class);
|
2005-11-16 04:53:48 +08:00
|
|
|
}
|
|
|
|
module_exit(cleanup_spu_base);
|
|
|
|
|
|
|
|
static int __init init_spu_base(void)
|
|
|
|
{
|
2006-10-04 23:26:12 +08:00
|
|
|
int i, ret;
|
2005-11-16 04:53:48 +08:00
|
|
|
|
2006-11-28 02:18:54 +08:00
|
|
|
if (!spu_management_ops)
|
|
|
|
return 0;
|
|
|
|
|
2006-06-20 02:33:19 +08:00
|
|
|
/* create sysdev class for spus */
|
|
|
|
ret = sysdev_class_register(&spu_sysdev_class);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2006-10-04 23:26:12 +08:00
|
|
|
for (i = 0; i < MAX_NUMNODES; i++)
|
|
|
|
INIT_LIST_HEAD(&spu_list[i]);
|
|
|
|
|
2006-11-23 07:46:49 +08:00
|
|
|
ret = spu_enumerate_spus(create_spu);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_WARNING "%s: Error initializing spus\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
cleanup_spu_base();
|
|
|
|
return ret;
|
2005-11-16 04:53:48 +08:00
|
|
|
}
|
2006-10-25 00:31:27 +08:00
|
|
|
|
|
|
|
xmon_register_spus(&spu_full_list);
|
|
|
|
|
2005-11-16 04:53:48 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
module_init(init_spu_base);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
|