From patchwork Wed Aug 28 01:44:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1977526 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=hvVmYl7z; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WtnKH1dwFz1yfn for ; Wed, 28 Aug 2024 11:44:51 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7D26688AAA; Wed, 28 Aug 2024 03:44:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="hvVmYl7z"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1BDEF88A8E; Wed, 28 Aug 2024 03:44:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E1B2C88A7B for ; Wed, 28 Aug 2024 03:44:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-829e856a173so99406639f.1 for ; Tue, 27 Aug 2024 18:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724809474; x=1725414274; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qdt/yQhGYtNjoMWAyHLJu0yyItecK5sjvsh7rw4oWPk=; b=hvVmYl7z6XjC5mnpvg+MwXXSdH2ihBpmMto8AjNLTWIIxDkdgIkriaPPWoSK5hpXpd YOl8Y9JIt/11poi3CRb9ZD8jGMJ9UfNdXiZOTb26GFAC1Dp3LIpvBxGqtKP6qCNcE3Cu PItFO8k0MZ3+4GyZGXGHEY9dsBsaDkH2D9atQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724809474; x=1725414274; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qdt/yQhGYtNjoMWAyHLJu0yyItecK5sjvsh7rw4oWPk=; b=C5C/IJbar+lWUI3aRyIVLKCyex3CyNJebjWL5XDTz67WV/3lgqQwWyB8utLql5Idjo 6HJzcaGmyhPgKi+Jcr9KigrqkLEOEFhJ+jrNtrKpeckyKzpssHSBXUP5tBrDJi24+Jjj F9dEk7mY1F1vtjKiqBeLvOuB69As2j6l3MXLPN6UCdtAu8FkNu17L+IdtGJqQy2Lr92f AmtBSR6N3y0OHBlFIUFo114bPYIosUjCINbsDRCKJgmvUpXjjPyMkUpsDN+KCHyv+8Mn O4GliHpyiX0NpsmhWtxDEfQ7KHTdckHQdtHp51Tln/6kHlVueMPd7npeB27JbOaF0NJm EQ3w== X-Gm-Message-State: AOJu0YxbarBFfHsgY+aF4Lh7dSRphEyBIBiZWZ9QSvNte4/YBXyjaavq Fowl6s/bNXRnB2QudocfOJ8DLvr/Fk8pNTccQeNxI87WeahMsqGfishLz6cbxN/venq1a0E1TIU = X-Google-Smtp-Source: AGHT+IG5CfeM8uDGLvtH2mIkkOfLBMVgpWBPoZFFyZgQrbvoELaj0MCNmLDc8lwRqjAOPSoAhPan+w== X-Received: by 2002:a05:6602:2c94:b0:824:e42e:a1bd with SMTP id ca18e2360f4ac-827881eb403mr1814354439f.17.1724809474576; Tue, 27 Aug 2024 18:44:34 -0700 (PDT) Received: from chromium.org (c-107-2-138-191.hsd1.co.comcast.net. [107.2.138.191]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-8253d3da8b9sm366342439f.0.2024.08.27.18.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 18:44:34 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Bin Meng , Tom Rini , Troy Kisky Subject: [PATCH 1/6] x86: Show the CPU vendor in bdinfo Date: Tue, 27 Aug 2024 19:44:24 -0600 Message-Id: <20240828014429.3320011-2-sjg@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828014429.3320011-1-sjg@chromium.org> References: <20240828014429.3320011-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Refactor the cpu code and use it to show the CPU vendor, e.g. AuthenticAMD or GenuineIntel Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- arch/x86/cpu/i386/cpu.c | 94 ++++++++++++++++++------------- arch/x86/include/asm/u-boot-x86.h | 8 +++ arch/x86/lib/bdinfo.c | 7 ++- 3 files changed, 69 insertions(+), 40 deletions(-) diff --git a/arch/x86/cpu/i386/cpu.c b/arch/x86/cpu/i386/cpu.c index 934e98ac582..101837b3190 100644 --- a/arch/x86/cpu/i386/cpu.c +++ b/arch/x86/cpu/i386/cpu.c @@ -263,6 +263,49 @@ static int build_vendor_name(char *vendor_name) } #endif +int x86_cpu_vendor_info(char *name) +{ + uint cpu_device; + + cpu_device = 0; + + /* gcc 7.3 does not want to drop x86_vendors, so use #ifdef */ +#ifndef CONFIG_TPL_BUILD + *name = '\0'; /* Unset */ + + /* Find the id and vendor_name */ + if (!has_cpuid()) { + /* Its a 486 if we can modify the AC flag */ + if (flag_is_changeable_p(X86_EFLAGS_AC)) + cpu_device = 0x00000400; /* 486 */ + else + cpu_device = 0x00000300; /* 386 */ + if (cpu_device == 0x00000400 && test_cyrix_52div()) { + /* If we ever care we can enable cpuid here */ + memcpy(name, "CyrixInstead", 13); + + /* Detect NexGen with old hypercode */ + } else if (deep_magic_nexgen_probe()) { + memcpy(name, "NexGenDriven", 13); + } + } else { + int cpuid_level; + + cpuid_level = build_vendor_name(name); + name[12] = '\0'; + + /* Intel-defined flags: level 0x00000001 */ + if (cpuid_level >= 0x00000001) + cpu_device = cpuid_eax(0x00000001); + else + /* Have CPUID level 0 only unheard of */ + cpu_device = 0x00000400; + } +#endif /* CONFIG_TPL_BUILD */ + + return cpu_device; +} + static void identify_cpu(struct cpu_device_id *cpu) { cpu->device = 0; /* fix gcc 4.4.4 warning */ @@ -289,46 +332,19 @@ static void identify_cpu(struct cpu_device_id *cpu) return; } -/* gcc 7.3 does not want to drop x86_vendors, so use #ifdef */ #ifndef CONFIG_TPL_BUILD - char vendor_name[16]; - int i; - - vendor_name[0] = '\0'; /* Unset */ - - /* Find the id and vendor_name */ - if (!has_cpuid()) { - /* Its a 486 if we can modify the AC flag */ - if (flag_is_changeable_p(X86_EFLAGS_AC)) - cpu->device = 0x00000400; /* 486 */ - else - cpu->device = 0x00000300; /* 386 */ - if ((cpu->device == 0x00000400) && test_cyrix_52div()) { - memcpy(vendor_name, "CyrixInstead", 13); - /* If we ever care we can enable cpuid here */ - } - /* Detect NexGen with old hypercode */ - else if (deep_magic_nexgen_probe()) - memcpy(vendor_name, "NexGenDriven", 13); - } else { - int cpuid_level; - - cpuid_level = build_vendor_name(vendor_name); - vendor_name[12] = '\0'; - - /* Intel-defined flags: level 0x00000001 */ - if (cpuid_level >= 0x00000001) { - cpu->device = cpuid_eax(0x00000001); - } else { - /* Have CPUID level 0 only unheard of */ - cpu->device = 0x00000400; - } - } - cpu->vendor = X86_VENDOR_UNKNOWN; - for (i = 0; i < ARRAY_SIZE(x86_vendors); i++) { - if (memcmp(vendor_name, x86_vendors[i].name, 12) == 0) { - cpu->vendor = x86_vendors[i].vendor; - break; + { + char vendor_name[16]; + int i; + + cpu->device = x86_cpu_vendor_info(vendor_name); + + cpu->vendor = X86_VENDOR_UNKNOWN; + for (i = 0; i < ARRAY_SIZE(x86_vendors); i++) { + if (memcmp(vendor_name, x86_vendors[i].name, 12) == 0) { + cpu->vendor = x86_vendors[i].vendor; + break; + } } } #endif diff --git a/arch/x86/include/asm/u-boot-x86.h b/arch/x86/include/asm/u-boot-x86.h index 3acc58ad74b..5cc8f63334e 100644 --- a/arch/x86/include/asm/u-boot-x86.h +++ b/arch/x86/include/asm/u-boot-x86.h @@ -51,6 +51,14 @@ int x86_cpu_init_tpl(void); */ void cpu_reinit_fpu(void); +/** + * x86_cpu_vendor_info() - Get the CPU-vendor name and device number + * + * @name: 13-byte area to hold the returned string + * Return: CPU device number read from cpuid + */ +int x86_cpu_vendor_info(char *name); + int cpu_init_f(void); void setup_gdt(struct global_data *id, u64 *gdt_addr); /* diff --git a/arch/x86/lib/bdinfo.c b/arch/x86/lib/bdinfo.c index 165e8ab944f..2a78f578dee 100644 --- a/arch/x86/lib/bdinfo.c +++ b/arch/x86/lib/bdinfo.c @@ -19,7 +19,12 @@ void arch_print_bdinfo(void) bdinfo_print_num_l("clock_rate", gd->arch.clock_rate); bdinfo_print_num_l("tsc_base", gd->arch.tsc_base); bdinfo_print_num_l("vendor", gd->arch.x86_vendor); - bdinfo_print_str(" name", cpu_vendor_name(gd->arch.x86_vendor)); + if (!IS_ENABLED(CONFIG_X86_64)) { + char vendor_name[16]; + + x86_cpu_vendor_info(vendor_name); + bdinfo_print_str(" name", vendor_name); + } bdinfo_print_num_l("model", gd->arch.x86_model); bdinfo_print_num_l("phys_addr in bits", cpu_phys_address_size()); bdinfo_print_num_l("table start", gd->arch.table_start); From patchwork Wed Aug 28 01:44:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1977527 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=KA1+7TvR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WtnKR65Hpz1yfn for ; Wed, 28 Aug 2024 11:44:59 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DDD7E88A7B; Wed, 28 Aug 2024 03:44:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="KA1+7TvR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1227488A8E; Wed, 28 Aug 2024 03:44:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A194E88A82 for ; Wed, 28 Aug 2024 03:44:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-829e856a14eso98058539f.2 for ; Tue, 27 Aug 2024 18:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724809475; x=1725414275; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=31RBrw/sCOf7pOdWYyBSNe+iQ4RRmPyJitIu9Aocug4=; b=KA1+7TvRTOzmURENTj4XTL4cNsv8kcCZFMVX0tYWpLOMZW7dgT1KV8jlCKNBr3P7RD pd3CEqHf2J41KVQswoPwn5xI6nTzBLcQpAQ0yzVr2lNjkvO7qwSfwp9vuoCTHpEkCdAE G5FCOMwUhRtqbiRFVK4++z1+a36IZ25gZbCzs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724809475; x=1725414275; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=31RBrw/sCOf7pOdWYyBSNe+iQ4RRmPyJitIu9Aocug4=; b=rVLdUMCmdC+RKcmmdv8VU6gOfoZ7zKME82PaEyh5ImiCgBunzSrvI0BqpfjUS8TkQ7 5ESCATH8893rfy8skl6yGO4jH/80rttdsBJt6wtGOexTAWZaJxFnlG/wtCqZd8iNHLlo lW4ydNnA2pP3pNeKE1f+STXJmfZZzo13Bt0ZIDOwT2uavSO88CsoVyglf6TVAQY0z5GE 6Iorml+qxT9MEiVsMBF2DDsnEADXyirnJtkTIzef33qtuvXiRi11VUety6bZNiGhe/d1 wI7HgO3ZeVmN0q+aotOcmIpAcsrycokN/r4IKWqonJ+odGAXy0Uv6dbhQS7r+Uf/oAM2 Nkwg== X-Gm-Message-State: AOJu0YxVvBEvS254/vs/8RJ97/dc8SjMTLeeB3Qq5GTcqyNIWcPf23iq 6QdJTGKB+XHjrCwQPOrXh8qqDVzDmeSeTdrQGplm984be7huuzp1UDtCHqhzz0KEcZ8ghBadpH0 = X-Google-Smtp-Source: AGHT+IHsq6Y5yAWMsoZ0ubgP7k3cvaHgsUSOAeAGFbRpZOdu7OQr1Vtk9NHnSWEH3voChd19MgkdmA== X-Received: by 2002:a05:6602:6b87:b0:804:2b28:75db with SMTP id ca18e2360f4ac-82787329bbemr1426889739f.10.1724809475283; Tue, 27 Aug 2024 18:44:35 -0700 (PDT) Received: from chromium.org (c-107-2-138-191.hsd1.co.comcast.net. [107.2.138.191]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-8253d3da8b9sm366342439f.0.2024.08.27.18.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 18:44:35 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Bin Meng , Tom Rini , Troy Kisky Subject: [PATCH 2/6] x86: Ensure the CPU identity exists for timer init Date: Tue, 27 Aug 2024 19:44:25 -0600 Message-Id: <20240828014429.3320011-3-sjg@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828014429.3320011-1-sjg@chromium.org> References: <20240828014429.3320011-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean When bootstage is used the timer can be inited before the CPU identity is set up, resulting in the checks for the vendor not working. Add a special call to work around this. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- arch/x86/cpu/i386/cpu.c | 5 +++++ arch/x86/cpu/x86_64/cpu.c | 6 ++++++ arch/x86/include/asm/u-boot-x86.h | 9 +++++++++ drivers/timer/tsc_timer.c | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/arch/x86/cpu/i386/cpu.c b/arch/x86/cpu/i386/cpu.c index 101837b3190..3726f7ff78f 100644 --- a/arch/x86/cpu/i386/cpu.c +++ b/arch/x86/cpu/i386/cpu.c @@ -501,6 +501,11 @@ int x86_cpu_reinit_f(void) return 0; } +void x86_get_identity_for_timer(void) +{ + setup_identity(); +} + void x86_enable_caches(void) { unsigned long cr0; diff --git a/arch/x86/cpu/x86_64/cpu.c b/arch/x86/cpu/x86_64/cpu.c index 80eab710315..71bc07f872a 100644 --- a/arch/x86/cpu/x86_64/cpu.c +++ b/arch/x86/cpu/x86_64/cpu.c @@ -75,3 +75,9 @@ void board_debug_uart_init(void) /* this was already done in SPL */ } #endif + +void x86_get_identity_for_timer(void) +{ + /* set the vendor to Intel so that native_calibrate_tsc() works */ + gd->arch.x86_vendor = X86_VENDOR_INTEL; +} diff --git a/arch/x86/include/asm/u-boot-x86.h b/arch/x86/include/asm/u-boot-x86.h index 5cc8f63334e..64139ead190 100644 --- a/arch/x86/include/asm/u-boot-x86.h +++ b/arch/x86/include/asm/u-boot-x86.h @@ -43,6 +43,15 @@ int x86_cpu_reinit_f(void); */ int x86_cpu_init_tpl(void); +/** + * x86_get_identity_for_timer() - Set up CPU identity for use by the early timer + * + * The timer can be needed early in board_f if bootstage is enabled. This + * function can be called from the TSC timer to make sure that the CPU-identity + * info has been set up + */ +void x86_get_identity_for_timer(void); + /** * cpu_reinit_fpu() - Reinit the FPU if something is wrong with it * diff --git a/drivers/timer/tsc_timer.c b/drivers/timer/tsc_timer.c index 80c084f380d..d11227cf440 100644 --- a/drivers/timer/tsc_timer.c +++ b/drivers/timer/tsc_timer.c @@ -403,6 +403,10 @@ static void tsc_timer_ensure_setup(bool early) if (!gd->arch.clock_rate) { unsigned long fast_calibrate; + /* deal with this being called before x86_cpu_init_f() */ + if (!gd->arch.x86_vendor) + x86_get_identity_for_timer(); + /** * There is no obvious way to obtain this information from EFI * boot services. This value was measured on a Framework Laptop From patchwork Wed Aug 28 01:44:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1977528 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=kyyzKZCt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WtnKd51vhz1yfy for ; Wed, 28 Aug 2024 11:45:09 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 49DA688AB1; Wed, 28 Aug 2024 03:44:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="kyyzKZCt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 95E6188AB9; Wed, 28 Aug 2024 03:44:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 761D488875 for ; Wed, 28 Aug 2024 03:44:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-829e856a159so99394239f.0 for ; Tue, 27 Aug 2024 18:44:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724809476; x=1725414276; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KDOiqFhz2OsOFW5+x4XSU9o6CZZXqfGYV7F7shvPuNg=; b=kyyzKZCth5wLPi9q3Q5WIBZe6DT/JDHfjPW2C016BPESHkaBxCacWg0OPG2+DrmFad kUidrttE5hUnAqHapw2OTv9CApKVRsFKPrE8M/xcm4gP5L/X/9xgZ9sf6/av5z6nOX6V jE/Fo0DCHXH+aQ2jWzDTGXYCO86sEvvY84N0A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724809476; x=1725414276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KDOiqFhz2OsOFW5+x4XSU9o6CZZXqfGYV7F7shvPuNg=; b=tXSoDsFGTmfCpv/MXkCYizIs0JVgnGkI1E2Gdmb48NYy3GJsDmE98YFMR4Za4XJXg2 70LJJgKxSallPVr1JyIml24EMcdngMMZhcxODEEtn4UuFG/QAwB6YA9RgF8/ovSa+xsr /vbonL7vIgj/TzGZsPkTPpPFBYim42cBG76pDs1jMTuSQYR9oFLMWqU/nEsOry6qsFqF UPyew4vhTjcF2bqFJU4IhQ58ijyc7DbyybDYD3ClN8coSvT85LwcZ0YkHodK/vGMciWs PqFpjZl07rA3QmBU1bYFlXCkiBvqUZxj4mgJ3pSdJoIWMrkd72NtEz4nk7AsYTnGCxq/ Qdjw== X-Gm-Message-State: AOJu0YwXdyi5uFOFd52jj4QcLAPejFLiAUTXhUZhm66o6i2LXihpcT4C C0HcWXl1bN2ic3nDXbcp8Lfmu/7/24lS/xfoUjLtZ+6M4DNs/+aS+Ppx6eslW4L7VUX0VXqm/Mc = X-Google-Smtp-Source: AGHT+IEY12qltEsnaa1g1Goj9mcgl50dWZFBP5NTtak2Ambih/c5voif0dWT0XBU4KO4yeflmu0kBA== X-Received: by 2002:a05:6602:2cc6:b0:824:d6bd:d6c9 with SMTP id ca18e2360f4ac-8278814184cmr1705613539f.9.1724809476008; Tue, 27 Aug 2024 18:44:36 -0700 (PDT) Received: from chromium.org (c-107-2-138-191.hsd1.co.comcast.net. [107.2.138.191]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-8253d3da8b9sm366342439f.0.2024.08.27.18.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 18:44:35 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Bin Meng , Tom Rini Subject: [PATCH 3/6] x86: Avoid timer-clock overflow Date: Tue, 27 Aug 2024 19:44:26 -0600 Message-Id: <20240828014429.3320011-4-sjg@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828014429.3320011-1-sjg@chromium.org> References: <20240828014429.3320011-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean When the clock speed is above about 4GHz, e.g. on modern PC hardware, the timer overflows, resulting in a much lower frequency than expected. Deal with this by capping the clock speed. It would be possible to move to a 64-bit value for the clock, but that is a pain to deal with. A better approach might be to express the clock in MHz but that is left for later consideration. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/timer/tsc_timer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/timer/tsc_timer.c b/drivers/timer/tsc_timer.c index d11227cf440..2f2c2f27b7f 100644 --- a/drivers/timer/tsc_timer.c +++ b/drivers/timer/tsc_timer.c @@ -442,6 +442,7 @@ static void tsc_timer_ensure_setup(bool early) return; done: + fast_calibrate = min(fast_calibrate, 4000UL); if (!gd->arch.clock_rate) gd->arch.clock_rate = fast_calibrate * 1000000; } From patchwork Wed Aug 28 01:44:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1977529 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=EiJi4PlB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WtnKq4Rd0z1yZd for ; Wed, 28 Aug 2024 11:45:19 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A7FBE88ADB; Wed, 28 Aug 2024 03:44:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="EiJi4PlB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9C89188ABA; Wed, 28 Aug 2024 03:44:40 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 856C188A7B for ; Wed, 28 Aug 2024 03:44:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-81fd925287eso226723839f.3 for ; Tue, 27 Aug 2024 18:44:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724809477; x=1725414277; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xVQN8EM8iMUv2XaqBR9jEHPxDJTZwcFT1oOYW3dlg60=; b=EiJi4PlBJa53o3Xrohi3z8u+C0HL0tewQBlUYR08K0iDkyR42IUBN06g5+uBSOUa3m IMfVhwWo+9QnjENzweuz00tS1HEYFE0L+i733fpY750in+8TyOX2kwS8Ew7AGIENPABV TdhzLpyWofXzMPonc9n6Vp22fc1uu/Y6DDTHA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724809477; x=1725414277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xVQN8EM8iMUv2XaqBR9jEHPxDJTZwcFT1oOYW3dlg60=; b=Hy7LpeacLtKM3lSxIqXu1lQBI6+OgLSYXNF/tf55AfbOhZmmhobvq9FCVZXrUAdqE+ GxFpgF/MYGWqV04VQ2yYLzTvM2Xr6HzI6ompoyz3u4L2YaCOVAyt66BPKu20cejsDauO EcFmsG21yLL+7BHkBXVvCwPaGf/Xyl6PJWmbdYmslqwl16QbqZ3a9/kOQzW2PmZLgFLg jNO4vBtP1jembzAl73BA4HgOJ3aaz0fjL4LCwS8203732UHt65S4LYIweY8QW9pg5xP5 Hss8scQMIHsFrJJKZQkA4Qz23LTItv7h85+GITCrAX6cKBGuzDm3N7rBhvmPulNnqJjr yEEQ== X-Gm-Message-State: AOJu0YyoaQvAbBn56RvMVLPsAMkG/z7i9EsKmTVEPlvb5Cf/OCm2GLTk 57LZVRo3XfWjiuAMXTMsgaMkAkIX/pWDdD1VjYjTaFFEaacl+EtMYq7sgJDpmJFu/Pk0ShPqSSc = X-Google-Smtp-Source: AGHT+IFcjnOjZhdq3WOOWOzUjY5D/6Y37PYaKGodIh+oRls4wzPNrRxfPHMoGymnT+u0EQ6xuxlABA== X-Received: by 2002:a05:6602:6c07:b0:822:3df4:64c5 with SMTP id ca18e2360f4ac-82a03e59785mr72733239f.9.1724809476993; Tue, 27 Aug 2024 18:44:36 -0700 (PDT) Received: from chromium.org (c-107-2-138-191.hsd1.co.comcast.net. [107.2.138.191]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-8253d3da8b9sm366342439f.0.2024.08.27.18.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 18:44:36 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Bin Meng , Tom Rini Subject: [PATCH 4/6] x86: Sync up tsc_timer with Linux Date: Tue, 27 Aug 2024 19:44:27 -0600 Message-Id: <20240828014429.3320011-5-sjg@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828014429.3320011-1-sjg@chromium.org> References: <20240828014429.3320011-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Since we are using the code from Linux, update it to the newer version in v6.11 Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/timer/tsc_timer.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/timer/tsc_timer.c b/drivers/timer/tsc_timer.c index 2f2c2f27b7f..dd16ab320b2 100644 --- a/drivers/timer/tsc_timer.c +++ b/drivers/timer/tsc_timer.c @@ -83,7 +83,7 @@ static unsigned long cpu_mhz_from_cpuid(void) if (cpuid_eax(0) < 0x16) return 0; - return cpuid_eax(0x16); + return cpuid_eax(0x15); } /* @@ -299,10 +299,19 @@ static unsigned long __maybe_unused quick_pit_calibrate(void) if (!pit_expect_msb(0xff-i, &delta, &d2)) break; + delta -= tsc; + + /* + * Extrapolate the error and fail fast if the error will + * never be below 500 ppm. + */ + if (i == 1 && + d1 + d2 >= (delta * MAX_QUICK_PIT_ITERATIONS) >> 11) + return 0; + /* * Iterate until the error is less than 500 ppm */ - delta -= tsc; if (d1+d2 >= delta >> 11) continue; From patchwork Wed Aug 28 01:44:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1977530 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Fu1yUb1r; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WtnL12hvqz1yZd for ; Wed, 28 Aug 2024 11:45:29 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0ACF888B16; Wed, 28 Aug 2024 03:44:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Fu1yUb1r"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A4EF88A7B; Wed, 28 Aug 2024 03:44:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 59BDF88A9D for ; Wed, 28 Aug 2024 03:44:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-81f921c418eso3232839f.0 for ; Tue, 27 Aug 2024 18:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724809478; x=1725414278; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w+1ZNAKpGLqqqk2ZF8ePuzkcZOfn0R8AwnIXNpQEuOs=; b=Fu1yUb1rsqdyBZosgKWCVzhsYFPAngEFc8+4eBf8Y1ye599xaFGt8hDRzkK9+2XqSl E+MsenHxpapIJjkWSnlmzvMRND+8mh84POzMc0AhechgIf5Ip5mLWg7udRDzefBvXk1D vYc5f5FrzgsvZ9vzIKsaeMSGdKYYEnVVBIOwo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724809478; x=1725414278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w+1ZNAKpGLqqqk2ZF8ePuzkcZOfn0R8AwnIXNpQEuOs=; b=bMPP44lp6OUAMTUzPhaR9RL/KogJqwu0a+okzlyGsy2fbnLmOSFXWiEhPCd4Cqi63P Gc8tvaOHiKBrYQ1/3plR79StNHmy+P5RiM4p1VSoIgT893UQzyNuNhZx7j2EkErcqYQ8 7m8A5mAYzv2Nm1Kk54I6AsHPgBIxoTF7qByynbWO10FRXXE7elgYdg1ghHsCi2nXB+c6 45x9uIZ9/VBI8/tms9GQFiRIvjkYhnCWxnGTNTEPWqAwx5ukGgJ2luEFohQmSE+gPUjW nXZBcRRmgsdGxYXQmZzj+aJv8enfu8098gAR6XjOOTXRn56AyBOtdkPbbZf2GdxPBVeF N8xg== X-Gm-Message-State: AOJu0YxwFWH75rGpP3OfgBEgL6zEo/v3iQtVXT4ghJhZQvr5mfomQTlA 0XhJq0RJEZhwNmf2FQnSfd2rCmKU/fGN+NhkFbCbor+910tY3ywdQXrOe+oy5yrvQr4NUlV5Okw = X-Google-Smtp-Source: AGHT+IE2csFFNwioLnziJv16vxilcMfVaf/EI9XcInYF5y+/2ijFVV76CMyQcQ31EhL53+9IXMgDfA== X-Received: by 2002:a05:6602:6197:b0:7f3:d85e:476f with SMTP id ca18e2360f4ac-82a03840903mr38242739f.6.1724809477911; Tue, 27 Aug 2024 18:44:37 -0700 (PDT) Received: from chromium.org (c-107-2-138-191.hsd1.co.comcast.net. [107.2.138.191]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-8253d3da8b9sm366342439f.0.2024.08.27.18.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 18:44:37 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Bin Meng , AKASHI Takahiro , Alexander Gendin , Francis Laniel , Heinrich Schuchardt , Hou Zhiqiang , Ilias Apalodimas , Maxim Moskalets , Rasmus Villemoes , Tom Fitzhenry , Tom Rini Subject: [PATCH 5/6] x86: Add a cpuid command Date: Tue, 27 Aug 2024 19:44:28 -0600 Message-Id: <20240828014429.3320011-6-sjg@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828014429.3320011-1-sjg@chromium.org> References: <20240828014429.3320011-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean It is useful to obtain the results of cpuid queries, so add a command for this. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- cmd/x86/Makefile | 2 +- cmd/x86/cpuid.c | 37 ++++++++++++++++++++++ doc/usage/cmd/cpuid.rst | 68 +++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + test/cmd/Makefile | 1 + test/cmd/cpuid.c | 22 +++++++++++++ 6 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 cmd/x86/cpuid.c create mode 100644 doc/usage/cmd/cpuid.rst create mode 100644 test/cmd/cpuid.c diff --git a/cmd/x86/Makefile b/cmd/x86/Makefile index b1f39d3bfde..1648907ac2d 100644 --- a/cmd/x86/Makefile +++ b/cmd/x86/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0+ obj-$(CONFIG_CMD_CBSYSINFO) += cbsysinfo.o -obj-y += mtrr.o +obj-y += cpuid.o mtrr.o obj-$(CONFIG_CMD_EXCEPTION) += exception.o obj-$(CONFIG_USE_HOB) += hob.o obj-$(CONFIG_HAVE_FSP) += fsp.o diff --git a/cmd/x86/cpuid.c b/cmd/x86/cpuid.c new file mode 100644 index 00000000000..222754b5d15 --- /dev/null +++ b/cmd/x86/cpuid.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * The 'cpuid' command provides access to the CPU's cpuid information + * + * Copyright 2024 Google, LLC + * Written by Simon Glass + */ + +#include +#include +#include + +static int do_cpuid(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct cpuid_result res; + ulong op; + + if (argc < 2) + return CMD_RET_USAGE; + + op = hextoul(argv[1], NULL); + res = cpuid(op); + printf("eax %08x\n", res.eax); + printf("ebx %08x\n", res.ebx); + printf("ecx %08x\n", res.ecx); + printf("edx %08x\n", res.edx); + + return 0; +} + +U_BOOT_LONGHELP(cpuid, "Show CPU Identification information"); + +U_BOOT_CMD( + cpuid, 2, 1, do_cpuid, + "cpuid ", cpuid_help_text +); diff --git a/doc/usage/cmd/cpuid.rst b/doc/usage/cmd/cpuid.rst new file mode 100644 index 00000000000..cccf9262ed4 --- /dev/null +++ b/doc/usage/cmd/cpuid.rst @@ -0,0 +1,68 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +.. index:: + single: cpuid (command) + +cpuid command +============= + +Synopsis +-------- + +:: + + cpuid + +Description +----------- + +The cpuid command requests CPU-identification information on x86 CPUs. The +operation selects what information is returned. Up to four 32-bit registers +can be update (eax-edx) depending on the operation. + +Configuration +------------- + +The cpuid command is only available on x86. + +Return value +------------ + +The return value $? is 0 (true). + +Example +------- + +:: + + => cpuid 1 + eax 00060fb1 + ebx 00040800 + ecx 80002001 + edx 178bfbfd + +This shows checking for 64-bit 'long' mode:: + + => cpuid 80000000 + eax 8000000a + ebx 68747541 + ecx 444d4163 + edx 69746e65 + => cpuid 80000001 + eax 00060fb1 + ebx 00000000 + ecx 00000007 + edx 2193fbfd # Bit 29 is set in edx, so long mode is available + +On a 32-bit-only CPU:: + + => cpuid 80000000 + eax 80000004 + ebx 756e6547 + ecx 6c65746e + edx 49656e69 + => cpuid 80000001 + eax 00000663 + ebx 00000000 + ecx 00000000 + edx 00000000 # Bit 29 is not set in edx, so long mode is not available diff --git a/doc/usage/index.rst b/doc/usage/index.rst index b058c2254fb..986554090af 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -52,6 +52,7 @@ Shell commands cmd/conitrace cmd/cp cmd/cpu + cmd/cpuid cmd/cyclic cmd/dm cmd/ebtupdate diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 8f2134998ad..dedcec33c8e 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -12,6 +12,7 @@ ifdef CONFIG_CONSOLE_RECORD obj-$(CONFIG_CMD_PAUSE) += test_pause.o endif obj-y += exit.o mem.o +obj-$(CONFIG_X86) += cpuid.o obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o obj-$(CONFIG_CMD_BDI) += bdinfo.o obj-$(CONFIG_CMD_FDT) += fdt.o diff --git a/test/cmd/cpuid.c b/test/cmd/cpuid.c new file mode 100644 index 00000000000..e07f5fd4696 --- /dev/null +++ b/test/cmd/cpuid.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for cpuid command + * + * Copyright 2024 Google LLC + * Written by Simon Glass + */ + +#include +#include + +static int cmd_test_cpuid(struct unit_test_state *uts) +{ + ut_assertok(run_commandf("cpuid 1")); + ut_assert_nextline("eax 00060fb1"); + ut_assert_nextline("ebx 00000800"); + ut_assert_nextline("ecx 80002001"); + ut_assert_nextline("edx 078bfbfd"); + + return 0; +} +CMD_TEST(cmd_test_cpuid, UTF_CONSOLE); From patchwork Wed Aug 28 01:44:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1977531 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=SjF1o/uy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WtnLC5gRtz1yZd for ; Wed, 28 Aug 2024 11:45:39 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 689E888B40; Wed, 28 Aug 2024 03:44:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="SjF1o/uy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8758F88875; Wed, 28 Aug 2024 03:44:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4C56B88AB1 for ; Wed, 28 Aug 2024 03:44:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-81fe38c7255so395961139f.1 for ; Tue, 27 Aug 2024 18:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724809479; x=1725414279; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UIY0u0AxH4yiUXGkDE1YJbyH3Tuygweo60MMmw97r2U=; b=SjF1o/uymcOxGU3BPZHigQPNVuwRutZ+sHm4swITpfhnSgLQEwI7M61XMPNsSVhmvI 7yWBb+a5FRG2+1ykbZ/2XjaLp5V4n2SktKeyo7ASkFcuwzg7SXMXVc/xzfxZ4MTbkkvR F7IeG1Yw7WApU0nQkrRRlLqRQfCLLxURZrbHc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724809479; x=1725414279; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UIY0u0AxH4yiUXGkDE1YJbyH3Tuygweo60MMmw97r2U=; b=otpVzsFYrhlWqvAmRqTJ6JGJqlUxWzyUX9HASTaTMyf4t+IrEyzjTBc+6HHwRdxxtZ 3lq0v7RHskRMbESfKsWB8IKEbEgOUizCYjPFeYq+ivoZh5Z6+Irq03uu40rwf18DA2cg gYMz6ikow0hQJfDvxBPYJnhjvM137Xjm00jQzSYylRUiioi+EcWUNrjowrpcvWnJ1+MA GewuXuWsuzVFuTEnHXF2HpDfpquYHcxjUauwGTyJ17SasAmwhBN8N6VRTWS7KwSV+iPA UtpqygMAE7qDxje3/eJZyyBgTD9dbJJwSWCFgnLg8cCVc3Oae6PdBEkJf6c1bd6WHzp5 UUlA== X-Gm-Message-State: AOJu0YzVUNAsSQdd0YHLEPig8UwxW42QwGwNg1XeDkjqj4ZBZnSQ60zI cT3ApgE+jo3pb5t2oXyuJMvysQZcbddisKf7Hz6CCRIDlbi5qXNM1y5Fe+8PaWKMjL9Z00bVgzA = X-Google-Smtp-Source: AGHT+IE3PJP1iewa87KluvfJRLMILVTUGRLELEdYHgBxgsoIeA78uow5KgL3URMRLAKNPTdsJoBWeA== X-Received: by 2002:a05:6602:340b:b0:81f:8c39:2a5c with SMTP id ca18e2360f4ac-82a04181c6bmr65875739f.12.1724809478852; Tue, 27 Aug 2024 18:44:38 -0700 (PDT) Received: from chromium.org (c-107-2-138-191.hsd1.co.comcast.net. [107.2.138.191]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-8253d3da8b9sm366342439f.0.2024.08.27.18.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 18:44:38 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Bin Meng , AKASHI Takahiro , Alexander Gendin , Eddie James , Etienne Carriere , Heinrich Schuchardt , Hou Zhiqiang , Ilias Apalodimas , Joshua Watt , Maxim Moskalets , Rasmus Villemoes , Tom Fitzhenry , Tom Rini Subject: [PATCH 6/6] x86: Add msr command Date: Tue, 27 Aug 2024 19:44:29 -0600 Message-Id: <20240828014429.3320011-7-sjg@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828014429.3320011-1-sjg@chromium.org> References: <20240828014429.3320011-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean It is useful to obtain the results of MSR queries as well as to update MSR registers, so add a command these tasks. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- cmd/x86/Makefile | 2 +- cmd/x86/msr.c | 52 ++++++++++++++++++++++++++++++++++++ doc/usage/cmd/msr.rst | 61 +++++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + test/cmd/Makefile | 2 +- test/cmd/msr.c | 38 +++++++++++++++++++++++++++ 6 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 cmd/x86/msr.c create mode 100644 doc/usage/cmd/msr.rst create mode 100644 test/cmd/msr.c diff --git a/cmd/x86/Makefile b/cmd/x86/Makefile index 1648907ac2d..925215235d3 100644 --- a/cmd/x86/Makefile +++ b/cmd/x86/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0+ obj-$(CONFIG_CMD_CBSYSINFO) += cbsysinfo.o -obj-y += cpuid.o mtrr.o +obj-y += cpuid.o msr.o mtrr.o obj-$(CONFIG_CMD_EXCEPTION) += exception.o obj-$(CONFIG_USE_HOB) += hob.o obj-$(CONFIG_HAVE_FSP) += fsp.o diff --git a/cmd/x86/msr.c b/cmd/x86/msr.c new file mode 100644 index 00000000000..3cb70d1f89a --- /dev/null +++ b/cmd/x86/msr.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * The 'cpuid' command provides access to the CPU's cpuid information + * + * Copyright 2024 Google, LLC + * Written by Simon Glass + */ + +#include +#include +#include + +static int do_read(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct msr_t msr; + ulong op; + + if (argc < 2) + return CMD_RET_USAGE; + + op = hextoul(argv[1], NULL); + msr = msr_read(op); + printf("%08x %08x\n", msr.hi, msr.lo); + + return 0; +} + +static int do_write(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct msr_t msr; + ulong op; + + if (argc < 4) + return CMD_RET_USAGE; + + op = hextoul(argv[1], NULL); + msr.hi = hextoul(argv[2], NULL); + msr.lo = hextoul(argv[3], NULL); + msr_write(op, msr); + + return 0; +} + +U_BOOT_LONGHELP(msr, + "read - read a machine-status register (MSR) as \n" + "write - write an MSR"); + +U_BOOT_CMD_WITH_SUBCMDS(msr, "Machine Status Registers", msr_help_text, + U_BOOT_CMD_MKENT(read, CONFIG_SYS_MAXARGS, 1, do_read, "", ""), + U_BOOT_CMD_MKENT(write, CONFIG_SYS_MAXARGS, 1, do_write, "", "")); diff --git a/doc/usage/cmd/msr.rst b/doc/usage/cmd/msr.rst new file mode 100644 index 00000000000..04ee52cc1c7 --- /dev/null +++ b/doc/usage/cmd/msr.rst @@ -0,0 +1,61 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +.. index:: + single: msr (command) + +msr command +=========== + +Synopsis +-------- + +:: + + msr read + msr write + +Description +----------- + +The msr command reads and writes machine-status registers (MSRs) on x86 CPUs. +The information is a 64-bit value split into two parts, for the top 32 +bits and for the bottom 32 bits. + +The operation selects what information is read or written. + +msr read +~~~~~~~~ + +This reads an MSR and displays the value obtained. + +msr write +~~~~~~~~~ + +This writes a value to an MSR. + +Configuration +------------- + +The msr command is only available on x86. + +Return value +------------ + +The return value $? is 0 (true). + +Example +------- + +This shows reading msr 0x194 which is MSR_FLEX_RATIO on Intel CPUs:: + + => msr read 194 + 00000000 00011200 # Bits 16 (flex ratio enable) and 20 (lock) are set + +This shows adjusting the energy-performance bias on an Intel CPU:: + + => msr read 1b0 + 00000000 00000006 # 6 means 'normal' + + => msr write 1b0 0 f # change to power-save + => msr read 1b0 + 00000000 0000000f diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 986554090af..2e60afb297e 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -87,6 +87,7 @@ Shell commands cmd/mbr cmd/md cmd/mmc + cmd/msr cmd/mtest cmd/mtrr cmd/panic diff --git a/test/cmd/Makefile b/test/cmd/Makefile index dedcec33c8e..fb6795a87a5 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -12,7 +12,7 @@ ifdef CONFIG_CONSOLE_RECORD obj-$(CONFIG_CMD_PAUSE) += test_pause.o endif obj-y += exit.o mem.o -obj-$(CONFIG_X86) += cpuid.o +obj-$(CONFIG_X86) += cpuid.o msr.o obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o obj-$(CONFIG_CMD_BDI) += bdinfo.o obj-$(CONFIG_CMD_FDT) += fdt.o diff --git a/test/cmd/msr.c b/test/cmd/msr.c new file mode 100644 index 00000000000..e9a152ee5bf --- /dev/null +++ b/test/cmd/msr.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for msr command + * + * Copyright 2024 Google LLC + * Written by Simon Glass + */ + +#include +#include + +static int cmd_test_msr(struct unit_test_state *uts) +{ + ut_assertok(run_commandf("msr read 200")); + ut_assert_nextline("00000000 ffe00006"); + ut_assert_console_end(); + + /* change the first variable msr and see it reflected in the mtrr cmd */ + ut_assertok(run_commandf("mtrr")); + ut_assert_nextline("CPU 65537:"); + ut_assert_nextlinen("Reg"); + ut_assert_nextlinen("0 Y Back 00000000ffe00000"); + ut_assertok(console_record_reset_enable()); + + /* change the type from 6 to 5 */ + ut_assertok(run_commandf("msr write 200 0 ffe00005")); + ut_assert_console_end(); + + /* Now it shows 'Protect' */ + ut_assertok(run_commandf("mtrr")); + ut_assert_nextline("CPU 65537:"); + ut_assert_nextlinen("Reg"); + ut_assert_nextlinen("0 Y Protect 00000000ffe00000"); + ut_assertok(console_record_reset_enable()); + + return 0; +} +CMD_TEST(cmd_test_msr, UTF_CONSOLE);