diff options
author | David S. Miller <davem@davemloft.net> | 2009-04-08 22:55:47 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-06-16 07:56:17 -0400 |
commit | 5052f525fde2dcb550cc3b4f15d2bfdd2a5c8782 (patch) | |
tree | 44ccbfe8843fa8d34d7c4e9756ae5eb9a5257d7b /arch | |
parent | 9bab54143ca16592536c9d35f43cfac0a2a28ea8 (diff) |
sparc64: Refactor MDESC cpu scanning code using an iterator.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/sparc/include/asm/mdesc.h | 1 | ||||
-rw-r--r-- | arch/sparc/kernel/mdesc.c | 146 |
2 files changed, 90 insertions, 57 deletions
diff --git a/arch/sparc/include/asm/mdesc.h b/arch/sparc/include/asm/mdesc.h index 1acc7272e537..8f8a520d14b9 100644 --- a/arch/sparc/include/asm/mdesc.h +++ b/arch/sparc/include/asm/mdesc.h | |||
@@ -72,6 +72,7 @@ struct mdesc_notifier_client { | |||
72 | extern void mdesc_register_notifier(struct mdesc_notifier_client *client); | 72 | extern void mdesc_register_notifier(struct mdesc_notifier_client *client); |
73 | 73 | ||
74 | extern void mdesc_fill_in_cpu_data(cpumask_t mask); | 74 | extern void mdesc_fill_in_cpu_data(cpumask_t mask); |
75 | extern void mdesc_populate_present_mask(cpumask_t *mask); | ||
75 | 76 | ||
76 | extern void sun4v_mdesc_init(void); | 77 | extern void sun4v_mdesc_init(void); |
77 | 78 | ||
diff --git a/arch/sparc/kernel/mdesc.c b/arch/sparc/kernel/mdesc.c index f0e6ed23a468..f50af3f9a2c9 100644 --- a/arch/sparc/kernel/mdesc.c +++ b/arch/sparc/kernel/mdesc.c | |||
@@ -574,7 +574,7 @@ static void __init report_platform_properties(void) | |||
574 | mdesc_release(hp); | 574 | mdesc_release(hp); |
575 | } | 575 | } |
576 | 576 | ||
577 | static void __devinit fill_in_one_cache(cpuinfo_sparc *c, | 577 | static void __cpuinit fill_in_one_cache(cpuinfo_sparc *c, |
578 | struct mdesc_handle *hp, | 578 | struct mdesc_handle *hp, |
579 | u64 mp) | 579 | u64 mp) |
580 | { | 580 | { |
@@ -619,8 +619,7 @@ static void __devinit fill_in_one_cache(cpuinfo_sparc *c, | |||
619 | } | 619 | } |
620 | } | 620 | } |
621 | 621 | ||
622 | static void __devinit mark_core_ids(struct mdesc_handle *hp, u64 mp, | 622 | static void __cpuinit mark_core_ids(struct mdesc_handle *hp, u64 mp, int core_id) |
623 | int core_id) | ||
624 | { | 623 | { |
625 | u64 a; | 624 | u64 a; |
626 | 625 | ||
@@ -653,7 +652,7 @@ static void __devinit mark_core_ids(struct mdesc_handle *hp, u64 mp, | |||
653 | } | 652 | } |
654 | } | 653 | } |
655 | 654 | ||
656 | static void __devinit set_core_ids(struct mdesc_handle *hp) | 655 | static void __cpuinit set_core_ids(struct mdesc_handle *hp) |
657 | { | 656 | { |
658 | int idx; | 657 | int idx; |
659 | u64 mp; | 658 | u64 mp; |
@@ -678,8 +677,7 @@ static void __devinit set_core_ids(struct mdesc_handle *hp) | |||
678 | } | 677 | } |
679 | } | 678 | } |
680 | 679 | ||
681 | static void __devinit mark_proc_ids(struct mdesc_handle *hp, u64 mp, | 680 | static void __cpuinit mark_proc_ids(struct mdesc_handle *hp, u64 mp, int proc_id) |
682 | int proc_id) | ||
683 | { | 681 | { |
684 | u64 a; | 682 | u64 a; |
685 | 683 | ||
@@ -698,8 +696,7 @@ static void __devinit mark_proc_ids(struct mdesc_handle *hp, u64 mp, | |||
698 | } | 696 | } |
699 | } | 697 | } |
700 | 698 | ||
701 | static void __devinit __set_proc_ids(struct mdesc_handle *hp, | 699 | static void __cpuinit __set_proc_ids(struct mdesc_handle *hp, const char *exec_unit_name) |
702 | const char *exec_unit_name) | ||
703 | { | 700 | { |
704 | int idx; | 701 | int idx; |
705 | u64 mp; | 702 | u64 mp; |
@@ -720,13 +717,13 @@ static void __devinit __set_proc_ids(struct mdesc_handle *hp, | |||
720 | } | 717 | } |
721 | } | 718 | } |
722 | 719 | ||
723 | static void __devinit set_proc_ids(struct mdesc_handle *hp) | 720 | static void __cpuinit set_proc_ids(struct mdesc_handle *hp) |
724 | { | 721 | { |
725 | __set_proc_ids(hp, "exec_unit"); | 722 | __set_proc_ids(hp, "exec_unit"); |
726 | __set_proc_ids(hp, "exec-unit"); | 723 | __set_proc_ids(hp, "exec-unit"); |
727 | } | 724 | } |
728 | 725 | ||
729 | static void __devinit get_one_mondo_bits(const u64 *p, unsigned int *mask, | 726 | static void __cpuinit get_one_mondo_bits(const u64 *p, unsigned int *mask, |
730 | unsigned char def) | 727 | unsigned char def) |
731 | { | 728 | { |
732 | u64 val; | 729 | u64 val; |
@@ -745,7 +742,7 @@ use_default: | |||
745 | *mask = ((1U << def) * 64U) - 1U; | 742 | *mask = ((1U << def) * 64U) - 1U; |
746 | } | 743 | } |
747 | 744 | ||
748 | static void __devinit get_mondo_data(struct mdesc_handle *hp, u64 mp, | 745 | static void __cpuinit get_mondo_data(struct mdesc_handle *hp, u64 mp, |
749 | struct trap_per_cpu *tb) | 746 | struct trap_per_cpu *tb) |
750 | { | 747 | { |
751 | const u64 *val; | 748 | const u64 *val; |
@@ -763,23 +760,15 @@ static void __devinit get_mondo_data(struct mdesc_handle *hp, u64 mp, | |||
763 | get_one_mondo_bits(val, &tb->nonresum_qmask, 2); | 760 | get_one_mondo_bits(val, &tb->nonresum_qmask, 2); |
764 | } | 761 | } |
765 | 762 | ||
766 | void __cpuinit mdesc_fill_in_cpu_data(cpumask_t mask) | 763 | static void * __cpuinit mdesc_iterate_over_cpus(void *(*func)(struct mdesc_handle *, u64, int, void *), void *arg, cpumask_t *mask) |
767 | { | 764 | { |
768 | struct mdesc_handle *hp = mdesc_grab(); | 765 | struct mdesc_handle *hp = mdesc_grab(); |
766 | void *ret = NULL; | ||
769 | u64 mp; | 767 | u64 mp; |
770 | 768 | ||
771 | ncpus_probed = 0; | ||
772 | mdesc_for_each_node_by_name(hp, mp, "cpu") { | 769 | mdesc_for_each_node_by_name(hp, mp, "cpu") { |
773 | const u64 *id = mdesc_get_property(hp, mp, "id", NULL); | 770 | const u64 *id = mdesc_get_property(hp, mp, "id", NULL); |
774 | const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL); | 771 | int cpuid = *id; |
775 | struct trap_per_cpu *tb; | ||
776 | cpuinfo_sparc *c; | ||
777 | int cpuid; | ||
778 | u64 a; | ||
779 | |||
780 | ncpus_probed++; | ||
781 | |||
782 | cpuid = *id; | ||
783 | 772 | ||
784 | #ifdef CONFIG_SMP | 773 | #ifdef CONFIG_SMP |
785 | if (cpuid >= NR_CPUS) { | 774 | if (cpuid >= NR_CPUS) { |
@@ -788,62 +777,105 @@ void __cpuinit mdesc_fill_in_cpu_data(cpumask_t mask) | |||
788 | cpuid, NR_CPUS); | 777 | cpuid, NR_CPUS); |
789 | continue; | 778 | continue; |
790 | } | 779 | } |
791 | if (!cpu_isset(cpuid, mask)) | 780 | if (!cpu_isset(cpuid, *mask)) |
792 | continue; | ||
793 | #else | ||
794 | /* On uniprocessor we only want the values for the | ||
795 | * real physical cpu the kernel booted onto, however | ||
796 | * cpu_data() only has one entry at index 0. | ||
797 | */ | ||
798 | if (cpuid != real_hard_smp_processor_id()) | ||
799 | continue; | 781 | continue; |
800 | cpuid = 0; | ||
801 | #endif | 782 | #endif |
802 | 783 | ||
803 | c = &cpu_data(cpuid); | 784 | ret = func(hp, mp, cpuid, arg); |
804 | c->clock_tick = *cfreq; | 785 | if (ret) |
786 | goto out; | ||
787 | } | ||
788 | out: | ||
789 | mdesc_release(hp); | ||
790 | return ret; | ||
791 | } | ||
805 | 792 | ||
806 | tb = &trap_block[cpuid]; | 793 | static void * __cpuinit record_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid, void *arg) |
807 | get_mondo_data(hp, mp, tb); | 794 | { |
795 | ncpus_probed++; | ||
796 | #ifdef CONFIG_SMP | ||
797 | set_cpu_present(cpuid, true); | ||
798 | #endif | ||
799 | return NULL; | ||
800 | } | ||
808 | 801 | ||
809 | mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { | 802 | void __cpuinit mdesc_populate_present_mask(cpumask_t *mask) |
810 | u64 j, t = mdesc_arc_target(hp, a); | 803 | { |
811 | const char *t_name; | 804 | if (tlb_type != hypervisor) |
805 | return; | ||
812 | 806 | ||
813 | t_name = mdesc_node_name(hp, t); | 807 | ncpus_probed = 0; |
814 | if (!strcmp(t_name, "cache")) { | 808 | mdesc_iterate_over_cpus(record_one_cpu, NULL, mask); |
815 | fill_in_one_cache(c, hp, t); | 809 | } |
816 | continue; | ||
817 | } | ||
818 | 810 | ||
819 | mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) { | 811 | static void * __cpuinit fill_in_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid, void *arg) |
820 | u64 n = mdesc_arc_target(hp, j); | 812 | { |
821 | const char *n_name; | 813 | const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL); |
814 | struct trap_per_cpu *tb; | ||
815 | cpuinfo_sparc *c; | ||
816 | u64 a; | ||
822 | 817 | ||
823 | n_name = mdesc_node_name(hp, n); | 818 | #ifndef CONFIG_SMP |
824 | if (!strcmp(n_name, "cache")) | 819 | /* On uniprocessor we only want the values for the |
825 | fill_in_one_cache(c, hp, n); | 820 | * real physical cpu the kernel booted onto, however |
826 | } | 821 | * cpu_data() only has one entry at index 0. |
822 | */ | ||
823 | if (cpuid != real_hard_smp_processor_id()) | ||
824 | return NULL; | ||
825 | cpuid = 0; | ||
826 | #endif | ||
827 | |||
828 | c = &cpu_data(cpuid); | ||
829 | c->clock_tick = *cfreq; | ||
830 | |||
831 | tb = &trap_block[cpuid]; | ||
832 | get_mondo_data(hp, mp, tb); | ||
833 | |||
834 | mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { | ||
835 | u64 j, t = mdesc_arc_target(hp, a); | ||
836 | const char *t_name; | ||
837 | |||
838 | t_name = mdesc_node_name(hp, t); | ||
839 | if (!strcmp(t_name, "cache")) { | ||
840 | fill_in_one_cache(c, hp, t); | ||
841 | continue; | ||
827 | } | 842 | } |
828 | 843 | ||
829 | #ifdef CONFIG_SMP | 844 | mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) { |
830 | cpu_set(cpuid, cpu_present_map); | 845 | u64 n = mdesc_arc_target(hp, j); |
831 | #endif | 846 | const char *n_name; |
832 | 847 | ||
833 | c->core_id = 0; | 848 | n_name = mdesc_node_name(hp, n); |
834 | c->proc_id = -1; | 849 | if (!strcmp(n_name, "cache")) |
850 | fill_in_one_cache(c, hp, n); | ||
851 | } | ||
835 | } | 852 | } |
836 | 853 | ||
854 | c->core_id = 0; | ||
855 | c->proc_id = -1; | ||
856 | |||
857 | return NULL; | ||
858 | } | ||
859 | |||
860 | void __cpuinit mdesc_fill_in_cpu_data(cpumask_t mask) | ||
861 | { | ||
862 | struct mdesc_handle *hp; | ||
863 | |||
864 | mdesc_populate_present_mask(&mask); | ||
865 | mdesc_iterate_over_cpus(fill_in_one_cpu, NULL, &mask); | ||
866 | |||
837 | #ifdef CONFIG_SMP | 867 | #ifdef CONFIG_SMP |
838 | sparc64_multi_core = 1; | 868 | sparc64_multi_core = 1; |
839 | #endif | 869 | #endif |
840 | 870 | ||
871 | hp = mdesc_grab(); | ||
872 | |||
841 | set_core_ids(hp); | 873 | set_core_ids(hp); |
842 | set_proc_ids(hp); | 874 | set_proc_ids(hp); |
843 | 875 | ||
844 | smp_fill_in_sib_core_maps(); | ||
845 | |||
846 | mdesc_release(hp); | 876 | mdesc_release(hp); |
877 | |||
878 | smp_fill_in_sib_core_maps(); | ||
847 | } | 879 | } |
848 | 880 | ||
849 | static ssize_t mdesc_read(struct file *file, char __user *buf, | 881 | static ssize_t mdesc_read(struct file *file, char __user *buf, |