[U-Boot] [PATCH v3 027/108] x86: Drop unnecessary cpu code for TPL

Bin Meng bmeng.cn at gmail.com
Mon Oct 28 12:56:57 UTC 2019


Hi Simon,

On Mon, Oct 21, 2019 at 11:40 AM Simon Glass <sjg at chromium.org> wrote:
>
> We don't need to know every detail about the CPU in TPL. Drop some
> superfluous functions to reduce code size. Add a simple CPU detection
> algorithm which just supports Intel and AMD, since we only support TPL
> on Intel, so far.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
>  arch/x86/cpu/cpu.c      |  4 ++++
>  arch/x86/cpu/i386/cpu.c | 41 +++++++++++++++++++++++++++++++++++++----
>  2 files changed, 41 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
> index 9ee4b0294ae..4795863b33c 100644
> --- a/arch/x86/cpu/cpu.c
> +++ b/arch/x86/cpu/cpu.c
> @@ -45,6 +45,7 @@
>
>  DECLARE_GLOBAL_DATA_PTR;
>
> +#ifndef CONFIG_TPL_BUILD
>  static const char *const x86_vendor_name[] = {
>         [X86_VENDOR_INTEL]     = "Intel",
>         [X86_VENDOR_CYRIX]     = "Cyrix",
> @@ -57,6 +58,7 @@ static const char *const x86_vendor_name[] = {
>         [X86_VENDOR_NSC]       = "NSC",
>         [X86_VENDOR_SIS]       = "SiS",
>  };
> +#endif
>
>  int __weak x86_cleanup_before_linux(void)
>  {
> @@ -113,6 +115,7 @@ int icache_status(void)
>         return 1;
>  }
>
> +#ifndef CONFIG_TPL_BUILD
>  const char *cpu_vendor_name(int vendor)
>  {
>         const char *name;
> @@ -123,6 +126,7 @@ const char *cpu_vendor_name(int vendor)
>
>         return name;
>  }
> +#endif
>
>  char *cpu_get_name(char *name)
>  {
> diff --git a/arch/x86/cpu/i386/cpu.c b/arch/x86/cpu/i386/cpu.c
> index 90b546e7410..5a14d42cb26 100644
> --- a/arch/x86/cpu/i386/cpu.c
> +++ b/arch/x86/cpu/i386/cpu.c
> @@ -20,6 +20,7 @@
>
>  #include <common.h>
>  #include <malloc.h>
> +#include <spl.h>
>  #include <asm/control_regs.h>
>  #include <asm/cpu.h>
>  #include <asm/mp.h>
> @@ -57,6 +58,8 @@ struct cpuinfo_x86 {
>         uint8_t x86_mask;
>  };
>
> +/* gcc 7.3 does not what to drop x86_vendors, so use #ifdef */

what => want ?

> +#ifndef CONFIG_TPL_BUILD
>  /*
>   * List of cpu vendor strings along with their normalized
>   * id values.
> @@ -77,6 +80,7 @@ static const struct {
>         { X86_VENDOR_NSC,       "Geode by NSC", },
>         { X86_VENDOR_SIS,       "SiS SiS SiS ", },
>  };
> +#endif
>
>  static void load_ds(u32 segment)
>  {
> @@ -229,6 +233,7 @@ static bool has_mtrr(void)
>         return cpuid_edx(0x00000001) & (1 << 12) ? true : false;
>  }
>
> +#ifndef CONFIG_TPL_BUILD
>  static int build_vendor_name(char *vendor_name)
>  {
>         struct cpuid_result result;
> @@ -241,14 +246,42 @@ static int build_vendor_name(char *vendor_name)
>
>         return result.eax;
>  }
> +#endif
>
>  static void identify_cpu(struct cpu_device_id *cpu)
>  {
> +       cpu->device = 0; /* fix gcc 4.4.4 warning */
> +
> +       /*
> +        * Do a quick and dirty check to save space - Intel and AMD only and
> +        * just the vendor. This is enough for most TPL code.
> +        */
> +       if (spl_phase() == PHASE_TPL) {
> +               struct cpuid_result result;
> +
> +               result = cpuid(0x00000000);
> +               switch (result.ecx >> 24) {
> +               case 'l': /* GenuineIntel */
> +                       cpu->vendor = X86_VENDOR_INTEL;
> +                       break;
> +               case 'D': /* AuthenticAMD */
> +                       cpu->vendor = X86_VENDOR_AMD;
> +                       break;
> +               default:
> +                       cpu->vendor = X86_VENDOR_ANY;
> +                       break;
> +               }
> +               if (0) /* Fix compiler warning */

Can we remove this completely?

> +                       deep_magic_nexgen_probe();
> +               return;
> +       }
> +
> +/* gcc 7.3 does not what to drop x86_vendors, so use #ifdef */

what?

> +#ifndef CONFIG_TPL_BUILD
>         char vendor_name[16];
>         int i;
>
>         vendor_name[0] = '\0'; /* Unset */
> -       cpu->device = 0; /* fix gcc 4.4.4 warning */
>
>         /* Find the id and vendor_name */
>         if (!has_cpuid()) {
> @@ -264,9 +297,8 @@ static void identify_cpu(struct cpu_device_id *cpu)
>                 /* Detect NexGen with old hypercode */
>                 else if (deep_magic_nexgen_probe())
>                         memcpy(vendor_name, "NexGenDriven", 13);
> -       }
> -       if (has_cpuid()) {
> -               int  cpuid_level;
> +       } else {
> +               int cpuid_level;
>
>                 cpuid_level = build_vendor_name(vendor_name);
>                 vendor_name[12] = '\0';
> @@ -286,6 +318,7 @@ static void identify_cpu(struct cpu_device_id *cpu)
>                         break;
>                 }
>         }
> +#endif
>  }
>
>  static inline void get_fms(struct cpuinfo_x86 *c, uint32_t tfms)
> --

Regards,
Bin


More information about the U-Boot mailing list