Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/cpufeature: Cleanup get_cpu_cap()

Add an enum for the ->x86_capability array indices and cleanup
get_cpu_cap() by killing some redundant local vars.

Signed-off-by: Borislav Petkov <bp@suse.de>
Link: http://lkml.kernel.org/r/1449481182-27541-3-git-send-email-bp@alien8.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

authored by

Borislav Petkov and committed by
Thomas Gleixner
39c06df4 2ccd71f1

+45 -28
+20
arch/x86/include/asm/cpufeature.h
··· 288 288 #include <asm/asm.h> 289 289 #include <linux/bitops.h> 290 290 291 + enum cpuid_leafs 292 + { 293 + CPUID_1_EDX = 0, 294 + CPUID_8000_0001_EDX, 295 + CPUID_8086_0001_EDX, 296 + CPUID_LNX_1, 297 + CPUID_1_ECX, 298 + CPUID_C000_0001_EDX, 299 + CPUID_8000_0001_ECX, 300 + CPUID_LNX_2, 301 + CPUID_LNX_3, 302 + CPUID_7_0_EBX, 303 + CPUID_D_1_EAX, 304 + CPUID_F_0_EDX, 305 + CPUID_F_1_EDX, 306 + CPUID_8000_0008_EBX, 307 + CPUID_6_EAX, 308 + CPUID_8000_000A_EDX, 309 + }; 310 + 291 311 #ifdef CONFIG_X86_FEATURE_NAMES 292 312 extern const char * const x86_cap_flags[NCAPINTS*32]; 293 313 extern const char * const x86_power_flags[32];
+1 -1
arch/x86/kernel/cpu/centaur.c
··· 43 43 /* store Centaur Extended Feature Flags as 44 44 * word 5 of the CPU capability bit array 45 45 */ 46 - c->x86_capability[5] = cpuid_edx(0xC0000001); 46 + c->x86_capability[CPUID_C000_0001_EDX] = cpuid_edx(0xC0000001); 47 47 } 48 48 #ifdef CONFIG_X86_32 49 49 /* Cyrix III family needs CX8 & PGE explicitly enabled. */
+22 -25
arch/x86/kernel/cpu/common.c
··· 599 599 600 600 void get_cpu_cap(struct cpuinfo_x86 *c) 601 601 { 602 - u32 tfms, xlvl; 603 - u32 ebx; 602 + u32 eax, ebx, ecx, edx; 604 603 605 604 /* Intel-defined flags: level 0x00000001 */ 606 605 if (c->cpuid_level >= 0x00000001) { 607 - u32 capability, excap; 606 + cpuid(0x00000001, &eax, &ebx, &ecx, &edx); 608 607 609 - cpuid(0x00000001, &tfms, &ebx, &excap, &capability); 610 - c->x86_capability[0] = capability; 611 - c->x86_capability[4] = excap; 608 + c->x86_capability[CPUID_1_ECX] = ecx; 609 + c->x86_capability[CPUID_1_EDX] = edx; 612 610 } 613 611 614 612 /* Additional Intel-defined flags: level 0x00000007 */ 615 613 if (c->cpuid_level >= 0x00000007) { 616 - u32 eax, ebx, ecx, edx; 617 - 618 614 cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx); 619 615 620 - c->x86_capability[9] = ebx; 616 + c->x86_capability[CPUID_7_0_EBX] = ebx; 621 617 622 - c->x86_capability[14] = cpuid_eax(0x00000006); 618 + c->x86_capability[CPUID_6_EAX] = cpuid_eax(0x00000006); 623 619 } 624 620 625 621 /* Extended state features: level 0x0000000d */ 626 622 if (c->cpuid_level >= 0x0000000d) { 627 - u32 eax, ebx, ecx, edx; 628 - 629 623 cpuid_count(0x0000000d, 1, &eax, &ebx, &ecx, &edx); 630 624 631 - c->x86_capability[10] = eax; 625 + c->x86_capability[CPUID_D_1_EAX] = eax; 632 626 } 633 627 634 628 /* Additional Intel-defined flags: level 0x0000000F */ 635 629 if (c->cpuid_level >= 0x0000000F) { 636 - u32 eax, ebx, ecx, edx; 637 630 638 631 /* QoS sub-leaf, EAX=0Fh, ECX=0 */ 639 632 cpuid_count(0x0000000F, 0, &eax, &ebx, &ecx, &edx); 640 - c->x86_capability[11] = edx; 633 + c->x86_capability[CPUID_F_0_EDX] = edx; 634 + 641 635 if (cpu_has(c, X86_FEATURE_CQM_LLC)) { 642 636 /* will be overridden if occupancy monitoring exists */ 643 637 c->x86_cache_max_rmid = ebx; 644 638 645 639 /* QoS sub-leaf, EAX=0Fh, ECX=1 */ 646 640 cpuid_count(0x0000000F, 1, &eax, &ebx, &ecx, &edx); 647 - c->x86_capability[12] = edx; 641 + c->x86_capability[CPUID_F_1_EDX] = edx; 642 + 648 643 if (cpu_has(c, X86_FEATURE_CQM_OCCUP_LLC)) { 649 644 c->x86_cache_max_rmid = ecx; 650 645 c->x86_cache_occ_scale = ebx; ··· 651 656 } 652 657 653 658 /* AMD-defined flags: level 0x80000001 */ 654 - xlvl = cpuid_eax(0x80000000); 655 - c->extended_cpuid_level = xlvl; 659 + eax = cpuid_eax(0x80000000); 660 + c->extended_cpuid_level = eax; 656 661 657 - if ((xlvl & 0xffff0000) == 0x80000000) { 658 - if (xlvl >= 0x80000001) { 659 - c->x86_capability[1] = cpuid_edx(0x80000001); 660 - c->x86_capability[6] = cpuid_ecx(0x80000001); 662 + if ((eax & 0xffff0000) == 0x80000000) { 663 + if (eax >= 0x80000001) { 664 + cpuid(0x80000001, &eax, &ebx, &ecx, &edx); 665 + 666 + c->x86_capability[CPUID_8000_0001_ECX] = ecx; 667 + c->x86_capability[CPUID_8000_0001_EDX] = edx; 661 668 } 662 669 } 663 670 664 671 if (c->extended_cpuid_level >= 0x80000008) { 665 - u32 eax = cpuid_eax(0x80000008); 672 + cpuid(0x80000008, &eax, &ebx, &ecx, &edx); 666 673 667 674 c->x86_virt_bits = (eax >> 8) & 0xff; 668 675 c->x86_phys_bits = eax & 0xff; 669 - c->x86_capability[13] = cpuid_ebx(0x80000008); 676 + c->x86_capability[CPUID_8000_0008_EBX] = ebx; 670 677 } 671 678 #ifdef CONFIG_X86_32 672 679 else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36)) ··· 679 682 c->x86_power = cpuid_edx(0x80000007); 680 683 681 684 if (c->extended_cpuid_level >= 0x8000000a) 682 - c->x86_capability[15] = cpuid_edx(0x8000000a); 685 + c->x86_capability[CPUID_8000_000A_EDX] = cpuid_edx(0x8000000a); 683 686 684 687 init_scattered_cpuid_features(c); 685 688 }
+2 -2
arch/x86/kernel/cpu/transmeta.c
··· 12 12 xlvl = cpuid_eax(0x80860000); 13 13 if ((xlvl & 0xffff0000) == 0x80860000) { 14 14 if (xlvl >= 0x80860001) 15 - c->x86_capability[2] = cpuid_edx(0x80860001); 15 + c->x86_capability[CPUID_8086_0001_EDX] = cpuid_edx(0x80860001); 16 16 } 17 17 } 18 18 ··· 82 82 /* Unhide possibly hidden capability flags */ 83 83 rdmsr(0x80860004, cap_mask, uk); 84 84 wrmsr(0x80860004, ~0, uk); 85 - c->x86_capability[0] = cpuid_edx(0x00000001); 85 + c->x86_capability[CPUID_1_EDX] = cpuid_edx(0x00000001); 86 86 wrmsr(0x80860004, cap_mask, uk); 87 87 88 88 /* All Transmeta CPUs have a constant TSC */