diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-02-28 13:37:06 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-02-28 13:37:06 -0500 |
commit | 58f02db466900003b801bdfdeddc4d96ce42b7d5 (patch) | |
tree | 3aec1f9f4aa147fde3facfe6c5f893ac667ce737 /arch/x86/kernel | |
parent | 43a834d86c136b31ef6ad796725eb474a55a908d (diff) | |
parent | cb19060abfdecac0d1eb2d2f0e7d6b7a3f8bc4f4 (diff) |
Merge branch 'x86-cpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'x86-cpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
x86, cacheinfo: Enable L3 CID only on AMD
x86, cacheinfo: Remove NUMA dependency, fix for AMD Fam10h rev D1
x86, cpu: Print AMD virtualization features in /proc/cpuinfo
x86, cacheinfo: Calculate L3 indices
x86, cacheinfo: Add cache index disable sysfs attrs only to L3 caches
x86, cacheinfo: Fix disabling of L3 cache indices
intel-agp: Switch to wbinvd_on_all_cpus
x86, lib: Add wbinvd smp helpers
Diffstat (limited to 'arch/x86/kernel')
-rw-r--r-- | arch/x86/kernel/cpu/addon_cpuid_features.c | 4 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/intel_cacheinfo.c | 250 |
2 files changed, 160 insertions, 94 deletions
diff --git a/arch/x86/kernel/cpu/addon_cpuid_features.c b/arch/x86/kernel/cpu/addon_cpuid_features.c index 468489b57aae..97ad79cdf688 100644 --- a/arch/x86/kernel/cpu/addon_cpuid_features.c +++ b/arch/x86/kernel/cpu/addon_cpuid_features.c | |||
@@ -32,6 +32,10 @@ void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c) | |||
32 | static const struct cpuid_bit __cpuinitconst cpuid_bits[] = { | 32 | static const struct cpuid_bit __cpuinitconst cpuid_bits[] = { |
33 | { X86_FEATURE_IDA, CR_EAX, 1, 0x00000006 }, | 33 | { X86_FEATURE_IDA, CR_EAX, 1, 0x00000006 }, |
34 | { X86_FEATURE_ARAT, CR_EAX, 2, 0x00000006 }, | 34 | { X86_FEATURE_ARAT, CR_EAX, 2, 0x00000006 }, |
35 | { X86_FEATURE_NPT, CR_EDX, 0, 0x8000000a }, | ||
36 | { X86_FEATURE_LBRV, CR_EDX, 1, 0x8000000a }, | ||
37 | { X86_FEATURE_SVML, CR_EDX, 2, 0x8000000a }, | ||
38 | { X86_FEATURE_NRIPS, CR_EDX, 3, 0x8000000a }, | ||
35 | { 0, 0, 0, 0 } | 39 | { 0, 0, 0, 0 } |
36 | }; | 40 | }; |
37 | 41 | ||
diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c index c2b722d5a722..eddb1bdd1b8f 100644 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <asm/processor.h> | 18 | #include <asm/processor.h> |
19 | #include <linux/smp.h> | 19 | #include <linux/smp.h> |
20 | #include <asm/k8.h> | 20 | #include <asm/k8.h> |
21 | #include <asm/smp.h> | ||
21 | 22 | ||
22 | #define LVL_1_INST 1 | 23 | #define LVL_1_INST 1 |
23 | #define LVL_1_DATA 2 | 24 | #define LVL_1_DATA 2 |
@@ -152,7 +153,8 @@ struct _cpuid4_info { | |||
152 | union _cpuid4_leaf_ebx ebx; | 153 | union _cpuid4_leaf_ebx ebx; |
153 | union _cpuid4_leaf_ecx ecx; | 154 | union _cpuid4_leaf_ecx ecx; |
154 | unsigned long size; | 155 | unsigned long size; |
155 | unsigned long can_disable; | 156 | bool can_disable; |
157 | unsigned int l3_indices; | ||
156 | DECLARE_BITMAP(shared_cpu_map, NR_CPUS); | 158 | DECLARE_BITMAP(shared_cpu_map, NR_CPUS); |
157 | }; | 159 | }; |
158 | 160 | ||
@@ -162,7 +164,8 @@ struct _cpuid4_info_regs { | |||
162 | union _cpuid4_leaf_ebx ebx; | 164 | union _cpuid4_leaf_ebx ebx; |
163 | union _cpuid4_leaf_ecx ecx; | 165 | union _cpuid4_leaf_ecx ecx; |
164 | unsigned long size; | 166 | unsigned long size; |
165 | unsigned long can_disable; | 167 | bool can_disable; |
168 | unsigned int l3_indices; | ||
166 | }; | 169 | }; |
167 | 170 | ||
168 | unsigned short num_cache_leaves; | 171 | unsigned short num_cache_leaves; |
@@ -292,6 +295,36 @@ amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax, | |||
292 | (ebx->split.ways_of_associativity + 1) - 1; | 295 | (ebx->split.ways_of_associativity + 1) - 1; |
293 | } | 296 | } |
294 | 297 | ||
298 | struct _cache_attr { | ||
299 | struct attribute attr; | ||
300 | ssize_t (*show)(struct _cpuid4_info *, char *); | ||
301 | ssize_t (*store)(struct _cpuid4_info *, const char *, size_t count); | ||
302 | }; | ||
303 | |||
304 | #ifdef CONFIG_CPU_SUP_AMD | ||
305 | static unsigned int __cpuinit amd_calc_l3_indices(void) | ||
306 | { | ||
307 | /* | ||
308 | * We're called over smp_call_function_single() and therefore | ||
309 | * are on the correct cpu. | ||
310 | */ | ||
311 | int cpu = smp_processor_id(); | ||
312 | int node = cpu_to_node(cpu); | ||
313 | struct pci_dev *dev = node_to_k8_nb_misc(node); | ||
314 | unsigned int sc0, sc1, sc2, sc3; | ||
315 | u32 val = 0; | ||
316 | |||
317 | pci_read_config_dword(dev, 0x1C4, &val); | ||
318 | |||
319 | /* calculate subcache sizes */ | ||
320 | sc0 = !(val & BIT(0)); | ||
321 | sc1 = !(val & BIT(4)); | ||
322 | sc2 = !(val & BIT(8)) + !(val & BIT(9)); | ||
323 | sc3 = !(val & BIT(12)) + !(val & BIT(13)); | ||
324 | |||
325 | return (max(max(max(sc0, sc1), sc2), sc3) << 10) - 1; | ||
326 | } | ||
327 | |||
295 | static void __cpuinit | 328 | static void __cpuinit |
296 | amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf) | 329 | amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf) |
297 | { | 330 | { |
@@ -301,12 +334,103 @@ amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf) | |||
301 | if (boot_cpu_data.x86 == 0x11) | 334 | if (boot_cpu_data.x86 == 0x11) |
302 | return; | 335 | return; |
303 | 336 | ||
304 | /* see erratum #382 */ | 337 | /* see errata #382 and #388 */ |
305 | if ((boot_cpu_data.x86 == 0x10) && (boot_cpu_data.x86_model < 0x8)) | 338 | if ((boot_cpu_data.x86 == 0x10) && |
339 | ((boot_cpu_data.x86_model < 0x8) || | ||
340 | (boot_cpu_data.x86_mask < 0x1))) | ||
306 | return; | 341 | return; |
307 | 342 | ||
308 | this_leaf->can_disable = 1; | 343 | this_leaf->can_disable = true; |
344 | this_leaf->l3_indices = amd_calc_l3_indices(); | ||
345 | } | ||
346 | |||
347 | static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf, | ||
348 | unsigned int index) | ||
349 | { | ||
350 | int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map)); | ||
351 | int node = amd_get_nb_id(cpu); | ||
352 | struct pci_dev *dev = node_to_k8_nb_misc(node); | ||
353 | unsigned int reg = 0; | ||
354 | |||
355 | if (!this_leaf->can_disable) | ||
356 | return -EINVAL; | ||
357 | |||
358 | if (!dev) | ||
359 | return -EINVAL; | ||
360 | |||
361 | pci_read_config_dword(dev, 0x1BC + index * 4, ®); | ||
362 | return sprintf(buf, "0x%08x\n", reg); | ||
363 | } | ||
364 | |||
365 | #define SHOW_CACHE_DISABLE(index) \ | ||
366 | static ssize_t \ | ||
367 | show_cache_disable_##index(struct _cpuid4_info *this_leaf, char *buf) \ | ||
368 | { \ | ||
369 | return show_cache_disable(this_leaf, buf, index); \ | ||
370 | } | ||
371 | SHOW_CACHE_DISABLE(0) | ||
372 | SHOW_CACHE_DISABLE(1) | ||
373 | |||
374 | static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf, | ||
375 | const char *buf, size_t count, unsigned int index) | ||
376 | { | ||
377 | int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map)); | ||
378 | int node = amd_get_nb_id(cpu); | ||
379 | struct pci_dev *dev = node_to_k8_nb_misc(node); | ||
380 | unsigned long val = 0; | ||
381 | |||
382 | #define SUBCACHE_MASK (3UL << 20) | ||
383 | #define SUBCACHE_INDEX 0xfff | ||
384 | |||
385 | if (!this_leaf->can_disable) | ||
386 | return -EINVAL; | ||
387 | |||
388 | if (!capable(CAP_SYS_ADMIN)) | ||
389 | return -EPERM; | ||
390 | |||
391 | if (!dev) | ||
392 | return -EINVAL; | ||
393 | |||
394 | if (strict_strtoul(buf, 10, &val) < 0) | ||
395 | return -EINVAL; | ||
396 | |||
397 | /* do not allow writes outside of allowed bits */ | ||
398 | if ((val & ~(SUBCACHE_MASK | SUBCACHE_INDEX)) || | ||
399 | ((val & SUBCACHE_INDEX) > this_leaf->l3_indices)) | ||
400 | return -EINVAL; | ||
401 | |||
402 | val |= BIT(30); | ||
403 | pci_write_config_dword(dev, 0x1BC + index * 4, val); | ||
404 | /* | ||
405 | * We need to WBINVD on a core on the node containing the L3 cache which | ||
406 | * indices we disable therefore a simple wbinvd() is not sufficient. | ||
407 | */ | ||
408 | wbinvd_on_cpu(cpu); | ||
409 | pci_write_config_dword(dev, 0x1BC + index * 4, val | BIT(31)); | ||
410 | return count; | ||
411 | } | ||
412 | |||
413 | #define STORE_CACHE_DISABLE(index) \ | ||
414 | static ssize_t \ | ||
415 | store_cache_disable_##index(struct _cpuid4_info *this_leaf, \ | ||
416 | const char *buf, size_t count) \ | ||
417 | { \ | ||
418 | return store_cache_disable(this_leaf, buf, count, index); \ | ||
309 | } | 419 | } |
420 | STORE_CACHE_DISABLE(0) | ||
421 | STORE_CACHE_DISABLE(1) | ||
422 | |||
423 | static struct _cache_attr cache_disable_0 = __ATTR(cache_disable_0, 0644, | ||
424 | show_cache_disable_0, store_cache_disable_0); | ||
425 | static struct _cache_attr cache_disable_1 = __ATTR(cache_disable_1, 0644, | ||
426 | show_cache_disable_1, store_cache_disable_1); | ||
427 | |||
428 | #else /* CONFIG_CPU_SUP_AMD */ | ||
429 | static void __cpuinit | ||
430 | amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf) | ||
431 | { | ||
432 | }; | ||
433 | #endif /* CONFIG_CPU_SUP_AMD */ | ||
310 | 434 | ||
311 | static int | 435 | static int |
312 | __cpuinit cpuid4_cache_lookup_regs(int index, | 436 | __cpuinit cpuid4_cache_lookup_regs(int index, |
@@ -713,82 +837,6 @@ static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf) | |||
713 | #define to_object(k) container_of(k, struct _index_kobject, kobj) | 837 | #define to_object(k) container_of(k, struct _index_kobject, kobj) |
714 | #define to_attr(a) container_of(a, struct _cache_attr, attr) | 838 | #define to_attr(a) container_of(a, struct _cache_attr, attr) |
715 | 839 | ||
716 | static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf, | ||
717 | unsigned int index) | ||
718 | { | ||
719 | int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map)); | ||
720 | int node = cpu_to_node(cpu); | ||
721 | struct pci_dev *dev = node_to_k8_nb_misc(node); | ||
722 | unsigned int reg = 0; | ||
723 | |||
724 | if (!this_leaf->can_disable) | ||
725 | return -EINVAL; | ||
726 | |||
727 | if (!dev) | ||
728 | return -EINVAL; | ||
729 | |||
730 | pci_read_config_dword(dev, 0x1BC + index * 4, ®); | ||
731 | return sprintf(buf, "%x\n", reg); | ||
732 | } | ||
733 | |||
734 | #define SHOW_CACHE_DISABLE(index) \ | ||
735 | static ssize_t \ | ||
736 | show_cache_disable_##index(struct _cpuid4_info *this_leaf, char *buf) \ | ||
737 | { \ | ||
738 | return show_cache_disable(this_leaf, buf, index); \ | ||
739 | } | ||
740 | SHOW_CACHE_DISABLE(0) | ||
741 | SHOW_CACHE_DISABLE(1) | ||
742 | |||
743 | static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf, | ||
744 | const char *buf, size_t count, unsigned int index) | ||
745 | { | ||
746 | int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map)); | ||
747 | int node = cpu_to_node(cpu); | ||
748 | struct pci_dev *dev = node_to_k8_nb_misc(node); | ||
749 | unsigned long val = 0; | ||
750 | unsigned int scrubber = 0; | ||
751 | |||
752 | if (!this_leaf->can_disable) | ||
753 | return -EINVAL; | ||
754 | |||
755 | if (!capable(CAP_SYS_ADMIN)) | ||
756 | return -EPERM; | ||
757 | |||
758 | if (!dev) | ||
759 | return -EINVAL; | ||
760 | |||
761 | if (strict_strtoul(buf, 10, &val) < 0) | ||
762 | return -EINVAL; | ||
763 | |||
764 | val |= 0xc0000000; | ||
765 | |||
766 | pci_read_config_dword(dev, 0x58, &scrubber); | ||
767 | scrubber &= ~0x1f000000; | ||
768 | pci_write_config_dword(dev, 0x58, scrubber); | ||
769 | |||
770 | pci_write_config_dword(dev, 0x1BC + index * 4, val & ~0x40000000); | ||
771 | wbinvd(); | ||
772 | pci_write_config_dword(dev, 0x1BC + index * 4, val); | ||
773 | return count; | ||
774 | } | ||
775 | |||
776 | #define STORE_CACHE_DISABLE(index) \ | ||
777 | static ssize_t \ | ||
778 | store_cache_disable_##index(struct _cpuid4_info *this_leaf, \ | ||
779 | const char *buf, size_t count) \ | ||
780 | { \ | ||
781 | return store_cache_disable(this_leaf, buf, count, index); \ | ||
782 | } | ||
783 | STORE_CACHE_DISABLE(0) | ||
784 | STORE_CACHE_DISABLE(1) | ||
785 | |||
786 | struct _cache_attr { | ||
787 | struct attribute attr; | ||
788 | ssize_t (*show)(struct _cpuid4_info *, char *); | ||
789 | ssize_t (*store)(struct _cpuid4_info *, const char *, size_t count); | ||
790 | }; | ||
791 | |||
792 | #define define_one_ro(_name) \ | 840 | #define define_one_ro(_name) \ |
793 | static struct _cache_attr _name = \ | 841 | static struct _cache_attr _name = \ |
794 | __ATTR(_name, 0444, show_##_name, NULL) | 842 | __ATTR(_name, 0444, show_##_name, NULL) |
@@ -803,23 +851,28 @@ define_one_ro(size); | |||
803 | define_one_ro(shared_cpu_map); | 851 | define_one_ro(shared_cpu_map); |
804 | define_one_ro(shared_cpu_list); | 852 | define_one_ro(shared_cpu_list); |
805 | 853 | ||
806 | static struct _cache_attr cache_disable_0 = __ATTR(cache_disable_0, 0644, | 854 | #define DEFAULT_SYSFS_CACHE_ATTRS \ |
807 | show_cache_disable_0, store_cache_disable_0); | 855 | &type.attr, \ |
808 | static struct _cache_attr cache_disable_1 = __ATTR(cache_disable_1, 0644, | 856 | &level.attr, \ |
809 | show_cache_disable_1, store_cache_disable_1); | 857 | &coherency_line_size.attr, \ |
858 | &physical_line_partition.attr, \ | ||
859 | &ways_of_associativity.attr, \ | ||
860 | &number_of_sets.attr, \ | ||
861 | &size.attr, \ | ||
862 | &shared_cpu_map.attr, \ | ||
863 | &shared_cpu_list.attr | ||
810 | 864 | ||
811 | static struct attribute *default_attrs[] = { | 865 | static struct attribute *default_attrs[] = { |
812 | &type.attr, | 866 | DEFAULT_SYSFS_CACHE_ATTRS, |
813 | &level.attr, | 867 | NULL |
814 | &coherency_line_size.attr, | 868 | }; |
815 | &physical_line_partition.attr, | 869 | |
816 | &ways_of_associativity.attr, | 870 | static struct attribute *default_l3_attrs[] = { |
817 | &number_of_sets.attr, | 871 | DEFAULT_SYSFS_CACHE_ATTRS, |
818 | &size.attr, | 872 | #ifdef CONFIG_CPU_SUP_AMD |
819 | &shared_cpu_map.attr, | ||
820 | &shared_cpu_list.attr, | ||
821 | &cache_disable_0.attr, | 873 | &cache_disable_0.attr, |
822 | &cache_disable_1.attr, | 874 | &cache_disable_1.attr, |
875 | #endif | ||
823 | NULL | 876 | NULL |
824 | }; | 877 | }; |
825 | 878 | ||
@@ -910,6 +963,7 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev) | |||
910 | unsigned int cpu = sys_dev->id; | 963 | unsigned int cpu = sys_dev->id; |
911 | unsigned long i, j; | 964 | unsigned long i, j; |
912 | struct _index_kobject *this_object; | 965 | struct _index_kobject *this_object; |
966 | struct _cpuid4_info *this_leaf; | ||
913 | int retval; | 967 | int retval; |
914 | 968 | ||
915 | retval = cpuid4_cache_sysfs_init(cpu); | 969 | retval = cpuid4_cache_sysfs_init(cpu); |
@@ -928,6 +982,14 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev) | |||
928 | this_object = INDEX_KOBJECT_PTR(cpu, i); | 982 | this_object = INDEX_KOBJECT_PTR(cpu, i); |
929 | this_object->cpu = cpu; | 983 | this_object->cpu = cpu; |
930 | this_object->index = i; | 984 | this_object->index = i; |
985 | |||
986 | this_leaf = CPUID4_INFO_IDX(cpu, i); | ||
987 | |||
988 | if (this_leaf->can_disable) | ||
989 | ktype_cache.default_attrs = default_l3_attrs; | ||
990 | else | ||
991 | ktype_cache.default_attrs = default_attrs; | ||
992 | |||
931 | retval = kobject_init_and_add(&(this_object->kobj), | 993 | retval = kobject_init_and_add(&(this_object->kobj), |
932 | &ktype_cache, | 994 | &ktype_cache, |
933 | per_cpu(ici_cache_kobject, cpu), | 995 | per_cpu(ici_cache_kobject, cpu), |