aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Detsch <adetsch@br.ibm.com>2007-08-03 21:53:46 -0400
committerPaul Mackerras <paulus@samba.org>2007-08-10 07:04:21 -0400
commitf5996449e3244524cab0ba709a4bd87047a8175f (patch)
treed25520e4020d148e6595270d93ddbb5f8224d083
parentedd0622bd2e8f755c960827e15aa6908c3c5aa94 (diff)
[POWERPC] cell: Move SPU affinity init to spu_management_of_ops
This patch moves affinity initialization code from spu_base.c to a new spu_management_of_ops function (init_affinity), which is empty in the case of PS3. This fixes a linking problem that was happening when compiling for PS3. Also, some small code style changes were made. Signed-off-by: Andre Detsch <adetsch@br.ibm.com> Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com> Acked-by: Arnd Bergmann <arnd.bergmann@de.ibm.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
-rw-r--r--arch/powerpc/platforms/cell/spu_base.c141
-rw-r--r--arch/powerpc/platforms/cell/spu_manage.c163
-rw-r--r--arch/powerpc/platforms/ps3/spu.c6
-rw-r--r--include/asm-powerpc/spu_priv1.h7
4 files changed, 177 insertions, 140 deletions
diff --git a/arch/powerpc/platforms/cell/spu_base.c b/arch/powerpc/platforms/cell/spu_base.c
index 90124228b8f4..095a30304c56 100644
--- a/arch/powerpc/platforms/cell/spu_base.c
+++ b/arch/powerpc/platforms/cell/spu_base.c
@@ -36,7 +36,6 @@
36#include <asm/spu_priv1.h> 36#include <asm/spu_priv1.h>
37#include <asm/xmon.h> 37#include <asm/xmon.h>
38#include <asm/prom.h> 38#include <asm/prom.h>
39#include "spu_priv1_mmio.h"
40 39
41const struct spu_management_ops *spu_management_ops; 40const struct spu_management_ops *spu_management_ops;
42EXPORT_SYMBOL_GPL(spu_management_ops); 41EXPORT_SYMBOL_GPL(spu_management_ops);
@@ -636,138 +635,6 @@ static ssize_t spu_stat_show(struct sys_device *sysdev, char *buf)
636 635
637static SYSDEV_ATTR(stat, 0644, spu_stat_show, NULL); 636static SYSDEV_ATTR(stat, 0644, spu_stat_show, NULL);
638 637
639/* Hardcoded affinity idxs for QS20 */
640#define SPES_PER_BE 8
641static int QS20_reg_idxs[SPES_PER_BE] = { 0, 2, 4, 6, 7, 5, 3, 1 };
642static int QS20_reg_memory[SPES_PER_BE] = { 1, 1, 0, 0, 0, 0, 0, 0 };
643
644static struct spu *spu_lookup_reg(int node, u32 reg)
645{
646 struct spu *spu;
647
648 list_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) {
649 if (*(u32 *)get_property(spu_devnode(spu), "reg", NULL) == reg)
650 return spu;
651 }
652 return NULL;
653}
654
655static void init_aff_QS20_harcoded(void)
656{
657 int node, i;
658 struct spu *last_spu, *spu;
659 u32 reg;
660
661 for (node = 0; node < MAX_NUMNODES; node++) {
662 last_spu = NULL;
663 for (i = 0; i < SPES_PER_BE; i++) {
664 reg = QS20_reg_idxs[i];
665 spu = spu_lookup_reg(node, reg);
666 if (!spu)
667 continue;
668 spu->has_mem_affinity = QS20_reg_memory[reg];
669 if (last_spu)
670 list_add_tail(&spu->aff_list,
671 &last_spu->aff_list);
672 last_spu = spu;
673 }
674 }
675}
676
677static int of_has_vicinity(void)
678{
679 struct spu* spu;
680
681 spu = list_entry(cbe_spu_info[0].spus.next, struct spu, cbe_list);
682 return of_find_property(spu_devnode(spu), "vicinity", NULL) != NULL;
683}
684
685static struct spu *aff_devnode_spu(int cbe, struct device_node *dn)
686{
687 struct spu *spu;
688
689 list_for_each_entry(spu, &cbe_spu_info[cbe].spus, cbe_list)
690 if (spu_devnode(spu) == dn)
691 return spu;
692 return NULL;
693}
694
695static struct spu *
696aff_node_next_to(int cbe, struct device_node *target, struct device_node *avoid)
697{
698 struct spu *spu;
699 const phandle *vic_handles;
700 int lenp, i;
701
702 list_for_each_entry(spu, &cbe_spu_info[cbe].spus, cbe_list) {
703 if (spu_devnode(spu) == avoid)
704 continue;
705 vic_handles = get_property(spu_devnode(spu), "vicinity", &lenp);
706 for (i=0; i < (lenp / sizeof(phandle)); i++) {
707 if (vic_handles[i] == target->linux_phandle)
708 return spu;
709 }
710 }
711 return NULL;
712}
713
714static void init_aff_fw_vicinity_node(int cbe)
715{
716 struct spu *spu, *last_spu;
717 struct device_node *vic_dn, *last_spu_dn;
718 phandle avoid_ph;
719 const phandle *vic_handles;
720 const char *name;
721 int lenp, i, added, mem_aff;
722
723 last_spu = list_entry(cbe_spu_info[cbe].spus.next, struct spu, cbe_list);
724 avoid_ph = 0;
725 for (added = 1; added < cbe_spu_info[cbe].n_spus; added++) {
726 last_spu_dn = spu_devnode(last_spu);
727 vic_handles = get_property(last_spu_dn, "vicinity", &lenp);
728
729 for (i = 0; i < (lenp / sizeof(phandle)); i++) {
730 if (vic_handles[i] == avoid_ph)
731 continue;
732
733 vic_dn = of_find_node_by_phandle(vic_handles[i]);
734 if (!vic_dn)
735 continue;
736
737 name = get_property(vic_dn, "name", NULL);
738 if (strcmp(name, "spe") == 0) {
739 spu = aff_devnode_spu(cbe, vic_dn);
740 avoid_ph = last_spu_dn->linux_phandle;
741 }
742 else {
743 mem_aff = strcmp(name, "mic-tm") == 0;
744 spu = aff_node_next_to(cbe, vic_dn, last_spu_dn);
745 if (!spu)
746 continue;
747 if (mem_aff) {
748 last_spu->has_mem_affinity = 1;
749 spu->has_mem_affinity = 1;
750 }
751 avoid_ph = vic_dn->linux_phandle;
752 }
753 list_add_tail(&spu->aff_list, &last_spu->aff_list);
754 last_spu = spu;
755 break;
756 }
757 }
758}
759
760static void init_aff_fw_vicinity(void)
761{
762 int cbe;
763
764 /* sets has_mem_affinity for each spu, as long as the
765 * spu->aff_list list, linking each spu to its neighbors
766 */
767 for (cbe = 0; cbe < MAX_NUMNODES; cbe++)
768 init_aff_fw_vicinity_node(cbe);
769}
770
771static int __init init_spu_base(void) 638static int __init init_spu_base(void)
772{ 639{
773 int i, ret = 0; 640 int i, ret = 0;
@@ -811,13 +678,7 @@ static int __init init_spu_base(void)
811 mutex_unlock(&spu_full_list_mutex); 678 mutex_unlock(&spu_full_list_mutex);
812 spu_add_sysdev_attr(&attr_stat); 679 spu_add_sysdev_attr(&attr_stat);
813 680
814 if (of_has_vicinity()) { 681 spu_init_affinity();
815 init_aff_fw_vicinity();
816 } else {
817 long root = of_get_flat_dt_root();
818 if (of_flat_dt_is_compatible(root, "IBM,CPBW-1.0"))
819 init_aff_QS20_harcoded();
820 }
821 682
822 return 0; 683 return 0;
823 684
diff --git a/arch/powerpc/platforms/cell/spu_manage.c b/arch/powerpc/platforms/cell/spu_manage.c
index 75ed50fcc3db..5eb88346181a 100644
--- a/arch/powerpc/platforms/cell/spu_manage.c
+++ b/arch/powerpc/platforms/cell/spu_manage.c
@@ -361,8 +361,171 @@ static int of_destroy_spu(struct spu *spu)
361 return 0; 361 return 0;
362} 362}
363 363
364/* Hardcoded affinity idxs for qs20 */
365#define QS20_SPES_PER_BE 8
366static int qs20_reg_idxs[QS20_SPES_PER_BE] = { 0, 2, 4, 6, 7, 5, 3, 1 };
367static int qs20_reg_memory[QS20_SPES_PER_BE] = { 1, 1, 0, 0, 0, 0, 0, 0 };
368
369static struct spu *spu_lookup_reg(int node, u32 reg)
370{
371 struct spu *spu;
372 u32 *spu_reg;
373
374 list_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) {
375 spu_reg = (u32*)of_get_property(spu_devnode(spu), "reg", NULL);
376 if (*spu_reg == reg)
377 return spu;
378 }
379 return NULL;
380}
381
382static void init_affinity_qs20_harcoded(void)
383{
384 int node, i;
385 struct spu *last_spu, *spu;
386 u32 reg;
387
388 for (node = 0; node < MAX_NUMNODES; node++) {
389 last_spu = NULL;
390 for (i = 0; i < QS20_SPES_PER_BE; i++) {
391 reg = qs20_reg_idxs[i];
392 spu = spu_lookup_reg(node, reg);
393 if (!spu)
394 continue;
395 spu->has_mem_affinity = qs20_reg_memory[reg];
396 if (last_spu)
397 list_add_tail(&spu->aff_list,
398 &last_spu->aff_list);
399 last_spu = spu;
400 }
401 }
402}
403
404static int of_has_vicinity(void)
405{
406 struct spu* spu;
407
408 spu = list_first_entry(&cbe_spu_info[0].spus, struct spu, cbe_list);
409 return of_find_property(spu_devnode(spu), "vicinity", NULL) != NULL;
410}
411
412static struct spu *devnode_spu(int cbe, struct device_node *dn)
413{
414 struct spu *spu;
415
416 list_for_each_entry(spu, &cbe_spu_info[cbe].spus, cbe_list)
417 if (spu_devnode(spu) == dn)
418 return spu;
419 return NULL;
420}
421
422static struct spu *
423neighbour_spu(int cbe, struct device_node *target, struct device_node *avoid)
424{
425 struct spu *spu;
426 struct device_node *spu_dn;
427 const phandle *vic_handles;
428 int lenp, i;
429
430 list_for_each_entry(spu, &cbe_spu_info[cbe].spus, cbe_list) {
431 spu_dn = spu_devnode(spu);
432 if (spu_dn == avoid)
433 continue;
434 vic_handles = of_get_property(spu_dn, "vicinity", &lenp);
435 for (i=0; i < (lenp / sizeof(phandle)); i++) {
436 if (vic_handles[i] == target->linux_phandle)
437 return spu;
438 }
439 }
440 return NULL;
441}
442
443static void init_affinity_node(int cbe)
444{
445 struct spu *spu, *last_spu;
446 struct device_node *vic_dn, *last_spu_dn;
447 phandle avoid_ph;
448 const phandle *vic_handles;
449 const char *name;
450 int lenp, i, added;
451
452 last_spu = list_first_entry(&cbe_spu_info[cbe].spus, struct spu,
453 cbe_list);
454 avoid_ph = 0;
455 for (added = 1; added < cbe_spu_info[cbe].n_spus; added++) {
456 last_spu_dn = spu_devnode(last_spu);
457 vic_handles = of_get_property(last_spu_dn, "vicinity", &lenp);
458
459 /*
460 * Walk through each phandle in vicinity property of the spu
461 * (tipically two vicinity phandles per spe node)
462 */
463 for (i = 0; i < (lenp / sizeof(phandle)); i++) {
464 if (vic_handles[i] == avoid_ph)
465 continue;
466
467 vic_dn = of_find_node_by_phandle(vic_handles[i]);
468 if (!vic_dn)
469 continue;
470
471 /* a neighbour might be spe, mic-tm, or bif0 */
472 name = of_get_property(vic_dn, "name", NULL);
473 if (!name)
474 continue;
475
476 if (strcmp(name, "spe") == 0) {
477 spu = devnode_spu(cbe, vic_dn);
478 avoid_ph = last_spu_dn->linux_phandle;
479 } else {
480 /*
481 * "mic-tm" and "bif0" nodes do not have
482 * vicinity property. So we need to find the
483 * spe which has vic_dn as neighbour, but
484 * skipping the one we came from (last_spu_dn)
485 */
486 spu = neighbour_spu(cbe, vic_dn, last_spu_dn);
487 if (!spu)
488 continue;
489 if (!strcmp(name, "mic-tm")) {
490 last_spu->has_mem_affinity = 1;
491 spu->has_mem_affinity = 1;
492 }
493 avoid_ph = vic_dn->linux_phandle;
494 }
495
496 list_add_tail(&spu->aff_list, &last_spu->aff_list);
497 last_spu = spu;
498 break;
499 }
500 }
501}
502
503static void init_affinity_fw(void)
504{
505 int cbe;
506
507 for (cbe = 0; cbe < MAX_NUMNODES; cbe++)
508 init_affinity_node(cbe);
509}
510
511static int __init init_affinity(void)
512{
513 if (of_has_vicinity()) {
514 init_affinity_fw();
515 } else {
516 long root = of_get_flat_dt_root();
517 if (of_flat_dt_is_compatible(root, "IBM,CPBW-1.0"))
518 init_affinity_qs20_harcoded();
519 else
520 printk("No affinity configuration found");
521 }
522
523 return 0;
524}
525
364const struct spu_management_ops spu_management_of_ops = { 526const struct spu_management_ops spu_management_of_ops = {
365 .enumerate_spus = of_enumerate_spus, 527 .enumerate_spus = of_enumerate_spus,
366 .create_spu = of_create_spu, 528 .create_spu = of_create_spu,
367 .destroy_spu = of_destroy_spu, 529 .destroy_spu = of_destroy_spu,
530 .init_affinity = init_affinity,
368}; 531};
diff --git a/arch/powerpc/platforms/ps3/spu.c b/arch/powerpc/platforms/ps3/spu.c
index 502d80ed982b..ac2a4b8a4c14 100644
--- a/arch/powerpc/platforms/ps3/spu.c
+++ b/arch/powerpc/platforms/ps3/spu.c
@@ -414,10 +414,16 @@ static int __init ps3_enumerate_spus(int (*fn)(void *data))
414 return num_resource_id; 414 return num_resource_id;
415} 415}
416 416
417static int ps3_init_affinity(void)
418{
419 return 0;
420}
421
417const struct spu_management_ops spu_management_ps3_ops = { 422const struct spu_management_ops spu_management_ps3_ops = {
418 .enumerate_spus = ps3_enumerate_spus, 423 .enumerate_spus = ps3_enumerate_spus,
419 .create_spu = ps3_create_spu, 424 .create_spu = ps3_create_spu,
420 .destroy_spu = ps3_destroy_spu, 425 .destroy_spu = ps3_destroy_spu,
426 .init_affinity = ps3_init_affinity,
421}; 427};
422 428
423/* spu_priv1_ops */ 429/* spu_priv1_ops */
diff --git a/include/asm-powerpc/spu_priv1.h b/include/asm-powerpc/spu_priv1.h
index 7e78f6a1ab8b..0f37c7c90820 100644
--- a/include/asm-powerpc/spu_priv1.h
+++ b/include/asm-powerpc/spu_priv1.h
@@ -178,6 +178,7 @@ struct spu_management_ops {
178 int (*enumerate_spus)(int (*fn)(void *data)); 178 int (*enumerate_spus)(int (*fn)(void *data));
179 int (*create_spu)(struct spu *spu, void *data); 179 int (*create_spu)(struct spu *spu, void *data);
180 int (*destroy_spu)(struct spu *spu); 180 int (*destroy_spu)(struct spu *spu);
181 int (*init_affinity)(void);
181}; 182};
182 183
183extern const struct spu_management_ops* spu_management_ops; 184extern const struct spu_management_ops* spu_management_ops;
@@ -200,6 +201,12 @@ spu_destroy_spu (struct spu *spu)
200 return spu_management_ops->destroy_spu(spu); 201 return spu_management_ops->destroy_spu(spu);
201} 202}
202 203
204static inline int
205spu_init_affinity (void)
206{
207 return spu_management_ops->init_affinity();
208}
209
203/* 210/*
204 * The declarations folowing are put here for convenience 211 * The declarations folowing are put here for convenience
205 * and only intended to be used by the platform setup code. 212 * and only intended to be used by the platform setup code.