]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
x86: Support CPU functions in long mode
authorSimon Glass <sjg@chromium.org>
Sat, 15 Mar 2025 14:25:41 +0000 (14:25 +0000)
committerTom Rini <trini@konsulko.com>
Thu, 3 Apr 2025 17:41:55 +0000 (11:41 -0600)
At present it is not possible to find out the physical-address size in
long mode, so a predefined value is used.

Update the macros to support this properly, since it is important when
programming MTRRs.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/x86/cpu/cpu.c
arch/x86/cpu/i386/cpu.c
arch/x86/cpu/x86_64/cpu.c
arch/x86/include/asm/cpu.h

index a8b21406ac06cc47ea6249691ba849cec7ec2527..c373b14df30c468efc781123e56568b78656e29c 100644 (file)
@@ -364,3 +364,27 @@ long locate_coreboot_table(void)
 
        return addr;
 }
+
+static bool has_cpuid(void)
+{
+       return flag_is_changeable_p(X86_EFLAGS_ID);
+}
+
+static uint cpu_cpuid_extended_level(void)
+{
+       return cpuid_eax(0x80000000);
+}
+
+int cpu_phys_address_size(void)
+{
+       if (!has_cpuid())
+               return 32;
+
+       if (cpu_cpuid_extended_level() >= 0x80000008)
+               return cpuid_eax(0x80000008) & 0xff;
+
+       if (cpuid_edx(1) & (CPUID_FEATURE_PAE | CPUID_FEATURE_PSE36))
+               return 36;
+
+       return 32;
+}
index b108f724c51d40cc26afa7752d372524edaf601f..ee6dbeb5c48e6575d9fd4f7041d02cf050a59b2a 100644 (file)
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define CPUID_FEATURE_PAE      BIT(6)
-#define CPUID_FEATURE_PSE36    BIT(17)
-#define CPUID_FEAURE_HTT       BIT(28)
-
 /*
  * Constructor for a conventional segment GDT (or LDT) entry
  * This is a macro so it can be used in initialisers
@@ -412,25 +408,6 @@ static void setup_identity(void)
        }
 }
 
-static uint cpu_cpuid_extended_level(void)
-{
-       return cpuid_eax(0x80000000);
-}
-
-int cpu_phys_address_size(void)
-{
-       if (!has_cpuid())
-               return 32;
-
-       if (cpu_cpuid_extended_level() >= 0x80000008)
-               return cpuid_eax(0x80000008) & 0xff;
-
-       if (cpuid_edx(1) & (CPUID_FEATURE_PAE | CPUID_FEATURE_PSE36))
-               return 36;
-
-       return 32;
-}
-
 static void setup_mtrr(void)
 {
        u64 mtrr_cap;
index 71bc07f872ad6bebbc7fe6cc323f4dc119adb44f..25ae92c702fbcad0a3f01f6d758e7b326447c730 100644 (file)
@@ -59,11 +59,6 @@ int x86_cpu_reinit_f(void)
        return 0;
 }
 
-int cpu_phys_address_size(void)
-{
-       return CONFIG_CPU_ADDR_BITS;
-}
-
 int x86_cpu_init_f(void)
 {
        return 0;
index fd389d4024c80f66fc000c6f1497b9ee02917884..1f1b545ea5071ed404bd7e0659eecc2c475a57da 100644 (file)
@@ -58,6 +58,10 @@ enum {
        X86_SYSCON_PUNIT,       /* Power unit */
 };
 
+#define CPUID_FEATURE_PAE      BIT(6)
+#define CPUID_FEATURE_PSE36    BIT(17)
+#define CPUID_FEAURE_HTT       BIT(28)
+
 struct cpuid_result {
        uint32_t eax;
        uint32_t ebx;
@@ -161,12 +165,16 @@ static inline unsigned int cpuid_edx(unsigned int op)
        return edx;
 }
 
-#if !CONFIG_IS_ENABLED(X86_64)
-
+#if CONFIG_IS_ENABLED(X86_64)
+static inline int flag_is_changeable_p(u32 flag)
+{
+       return 1;
+}
+#else
 /* Standard macro to see if a specific flag is changeable */
-static inline int flag_is_changeable_p(uint32_t flag)
+static inline int flag_is_changeable_p(u32 flag)
 {
-       uint32_t f1, f2;
+       u32 f1, f2;
 
        asm(
                "pushfl\n\t"
@@ -181,9 +189,9 @@ static inline int flag_is_changeable_p(uint32_t flag)
                "popfl\n\t"
                : "=&r" (f1), "=&r" (f2)
                : "ir" (flag));
-       return ((f1^f2) & flag) != 0;
+       return ((f1 ^ f2) & flag) != 0;
 }
-#endif
+#endif /* X86_64 */
 
 /**
  * cpu_enable_paging_pae() - Enable PAE-paging