21 #include <linux/kernel.h>
23 #include <linux/slab.h>
25 #include <linux/export.h>
34 #include "../cell/spufs/spufs.h"
133 #define dump_areas(_a, _b, _c, _d, _e) \
134 _dump_areas(_a, _b, _c, _d, _e, __func__, __LINE__)
135 static void _dump_areas(
unsigned int spe_id,
unsigned long priv2,
136 unsigned long problem,
unsigned long ls,
unsigned long shadow,
139 pr_debug(
"%s:%d: spe_id: %xh (%u)\n", func, line, spe_id, spe_id);
140 pr_debug(
"%s:%d: priv2: %lxh\n", func, line, priv2);
141 pr_debug(
"%s:%d: problem: %lxh\n", func, line, problem);
142 pr_debug(
"%s:%d: ls: %lxh\n", func, line, ls);
143 pr_debug(
"%s:%d: shadow: %lxh\n", func, line, shadow);
152 static unsigned long get_vas_id(
void)
157 lv1_get_virtual_address_space_id_of_ppe(&
id);
162 static int __init construct_spu(
struct spu *spu)
167 u64 local_store_phys;
172 &local_store_phys, &unused,
175 spu->problem_phys = problem_phys;
176 spu->local_store_phys = local_store_phys;
179 pr_debug(
"%s:%d: lv1_construct_logical_spe failed: %s\n",
180 __func__, __LINE__, ps3_result(result));
187 static void spu_unmap(
struct spu *spu)
205 static int __init setup_areas(
struct spu *spu)
214 pr_debug(
"%s:%d: ioremap shadow failed\n", __func__, __LINE__);
221 if (!spu->local_store) {
222 pr_debug(
"%s:%d: ioremap local_store failed\n",
227 spu->problem =
ioremap(spu->problem_phys,
228 sizeof(
struct spu_problem));
231 pr_debug(
"%s:%d: ioremap problem failed\n", __func__, __LINE__);
236 sizeof(
struct spu_priv2));
239 pr_debug(
"%s:%d: ioremap priv2 failed\n", __func__, __LINE__);
244 spu->problem_phys, spu->local_store_phys,
247 (
unsigned long)spu->problem, (
unsigned long)spu->local_store,
258 static int __init setup_interrupts(
struct spu *spu)
287 spu->irqs[0] = spu->irqs[1] = spu->irqs[2] =
NO_IRQ;
291 static int __init enable_spu(
struct spu *spu)
295 result = lv1_enable_logical_spe(
spu_pdata(spu)->spe_id,
299 pr_debug(
"%s:%d: lv1_enable_logical_spe failed: %s\n",
300 __func__, __LINE__, ps3_result(result));
304 result = setup_areas(spu);
309 result = setup_interrupts(spu);
312 goto fail_interrupts;
319 lv1_disable_logical_spe(
spu_pdata(spu)->spe_id, 0);
324 static int ps3_destroy_spu(
struct spu *spu)
328 pr_debug(
"%s:%d spu_%d\n", __func__, __LINE__, spu->number);
330 result = lv1_disable_logical_spe(
spu_pdata(spu)->spe_id, 0);
337 spu->irqs[0] = spu->irqs[1] = spu->irqs[2] =
NO_IRQ;
341 result = lv1_destruct_logical_spe(
spu_pdata(spu)->spe_id);
350 static int __init ps3_create_spu(
struct spu *spu,
void *
data)
354 pr_debug(
"%s:%d spu_%d\n", __func__, __LINE__, spu->number);
356 spu->pdata = kzalloc(
sizeof(
struct spu_pdata),
370 result = construct_spu(spu);
377 result = enable_spu(spu);
393 ps3_destroy_spu(spu);
398 static int __init ps3_enumerate_spus(
int (*
fn)(
void *data))
401 unsigned int num_resource_id;
406 pr_debug(
"%s:%d: num_resource_id %u\n", __func__, __LINE__,
414 for (i = 0; i < num_resource_id; i++) {
416 unsigned int resource_id;
419 &resource_type, &resource_id);
425 result =
fn((
void*)(
unsigned long)resource_id);
438 return num_resource_id;
441 static int ps3_init_affinity(
void)
465 ctx->
ops->runcntl_stop(ctx);
469 .enumerate_spus = ps3_enumerate_spus,
470 .create_spu = ps3_create_spu,
471 .destroy_spu = ps3_destroy_spu,
472 .enable_spu = ps3_enable_spu,
473 .disable_spu = ps3_disable_spu,
474 .init_affinity = ps3_init_affinity,
479 static void int_mask_and(
struct spu *spu,
int class,
u64 mask)
484 old_mask = spu_int_mask_get(spu,
class);
485 spu_int_mask_set(spu,
class, old_mask & mask);
488 static void int_mask_or(
struct spu *spu,
int class,
u64 mask)
492 old_mask = spu_int_mask_get(spu,
class);
493 spu_int_mask_set(spu,
class, old_mask | mask);
496 static void int_mask_set(
struct spu *spu,
int class,
u64 mask)
499 lv1_set_spe_interrupt_mask(
spu_pdata(spu)->spe_id,
class,
503 static u64 int_mask_get(
struct spu *spu,
int class)
508 static void int_stat_clear(
struct spu *spu,
int class,
u64 stat)
512 lv1_clear_spe_interrupt_status(
spu_pdata(spu)->spe_id,
class,
516 static u64 int_stat_get(
struct spu *spu,
int class)
520 lv1_get_spe_interrupt_status(
spu_pdata(spu)->spe_id,
class, &stat);
529 static u64 mfc_dar_get(
struct spu *spu)
534 static void mfc_dsisr_set(
struct spu *spu,
u64 dsisr)
539 static u64 mfc_dsisr_get(
struct spu *spu)
544 static void mfc_sdr_setup(
struct spu *spu)
549 static void mfc_sr1_set(
struct spu *spu,
u64 sr1)
553 static const u64 allowed = ~(MFC_STATE1_LOCAL_STORAGE_DECODE_MASK
554 | MFC_STATE1_PROBLEM_STATE_MASK);
559 lv1_set_spe_privilege_state_area_1_register(
561 offsetof(
struct spu_priv1, mfc_sr1_RW),
565 static u64 mfc_sr1_get(
struct spu *spu)
570 static void mfc_tclass_id_set(
struct spu *spu,
u64 tclass_id)
573 lv1_set_spe_privilege_state_area_1_register(
575 offsetof(
struct spu_priv1, mfc_tclass_id_RW),
579 static u64 mfc_tclass_id_get(
struct spu *spu)
584 static void tlb_invalidate(
struct spu *spu)
589 static void resource_allocation_groupID_set(
struct spu *spu,
u64 id)
594 static u64 resource_allocation_groupID_get(
struct spu *spu)
599 static void resource_allocation_enable_set(
struct spu *spu,
u64 enable)
604 static u64 resource_allocation_enable_get(
struct spu *spu)
610 .int_mask_and = int_mask_and,
611 .int_mask_or = int_mask_or,
612 .int_mask_set = int_mask_set,
613 .int_mask_get = int_mask_get,
614 .int_stat_clear = int_stat_clear,
615 .int_stat_get = int_stat_get,
617 .mfc_dar_get = mfc_dar_get,
618 .mfc_dsisr_set = mfc_dsisr_set,
619 .mfc_dsisr_get = mfc_dsisr_get,
620 .mfc_sdr_setup = mfc_sdr_setup,
621 .mfc_sr1_set = mfc_sr1_set,
622 .mfc_sr1_get = mfc_sr1_get,
623 .mfc_tclass_id_set = mfc_tclass_id_set,
624 .mfc_tclass_id_get = mfc_tclass_id_get,
625 .tlb_invalidate = tlb_invalidate,
626 .resource_allocation_groupID_set = resource_allocation_groupID_set,
627 .resource_allocation_groupID_get = resource_allocation_groupID_get,
628 .resource_allocation_enable_set = resource_allocation_enable_set,
629 .resource_allocation_enable_get = resource_allocation_enable_get,