From patchwork Mon Jan 27 05:06:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229580 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=SWVQKGLK; dkim-atps=neutral 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485dSM0lVpz9sR1 for ; Mon, 27 Jan 2020 16:23:14 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8BB4181904; Mon, 27 Jan 2020 06:13:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="SWVQKGLK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E57F88173E; Mon, 27 Jan 2020 06:10:12 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 3D652817B4 for ; Mon, 27 Jan 2020 06:09:31 +0100 (CET) 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-xd42.google.com with SMTP id s24so7030038iog.5 for ; Sun, 26 Jan 2020 21:09:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u+Jy2Bl5JhPWxyylGzF/zTox3Vi97L3iUPZ1uIBY11s=; b=SWVQKGLKMnczi2CpYU+eG+HCxPgQliyXk+EU/APo5Ae1FqzNlUC078WOxBaqo6YaPh zt+4XOg7Scnh099SNKlWQm+RT/AyCEMDzb2hqNViv5VKIhf1Taffjq8v7ZA95t4lJ364 ifDOy4vaeZINAQ24LJkNBmw6PY8NYn7EMiFa0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u+Jy2Bl5JhPWxyylGzF/zTox3Vi97L3iUPZ1uIBY11s=; b=kb+vCJfND6LPPI/HHcVMNnAOQbSBijZEsuYyuMGxTj/vrsLM5upWIOm3LgvjlJGHKx 2zXcLZY8eE5wvWqVArrgcK0CwpUuyRyPkm4yikCDRtL4b/5iV/DiBhduJvsPfjsrDoBE VUHMXBqqfKPcMH4lYF9q7TPM65qOXxprPlzQC4qh6cuu/JN1DeNueLZAi8edIAS6qDLt N6SkjO4+uBDcWS0Q7xGadR2fWKkU9baoXDWWFUZL2ijLgMGh+/VD9Rqu0Tg7GkozteNF OcAhDelfqDabZA3JXAg2mNGGF9jSCHgHsFVcy3mHdWaPCF1WEIgrsYpJ2iQjqXqgkYu2 rTZw== X-Gm-Message-State: APjAAAVAA60bdA6hfPOqi2Tv3O/77/CB7MHWT1syzgqh1L7t9nRUoHa6 +8LwZ2YoVGevLs6KbrF1SA+iMKoFcAQwgg== X-Google-Smtp-Source: APXvYqwqY/vTXhEc4My0LlKDADVfFS+5gdsPOnDPDuGM9rArFz48wNsBayX3ZwdKCr2M2MDs6gLFFA== X-Received: by 2002:a02:c611:: with SMTP id i17mr12221776jan.28.1580101769843; Sun, 26 Jan 2020 21:09:29 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h23sm4313195ilf.57.2020.01.26.21.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 21:09:29 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 082/108] x86: Add a few common Intel CPU functions Date: Sun, 26 Jan 2020 22:06:29 -0700 Message-Id: <20200126220508.82.I9e5c6c23522c6d47c569dccf41bfa7b48aeb554b@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127050655.170614-1-sjg@chromium.org> References: <20200127050655.170614-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 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.101.4 at phobos.denx.de X-Virus-Status: Clean Add functions to query CPU information, needed for ACPI. Signed-off-by: Simon Glass --- arch/x86/cpu/intel_common/cpu.c | 59 +++++++++++++++++++++++++++++++ arch/x86/include/asm/cpu_common.h | 31 ++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/arch/x86/cpu/intel_common/cpu.c b/arch/x86/cpu/intel_common/cpu.c index 4d093a5391..106ff41e23 100644 --- a/arch/x86/cpu/intel_common/cpu.c +++ b/arch/x86/cpu/intel_common/cpu.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -226,3 +227,61 @@ void cpu_set_eist(bool eist_status) msr.lo &= ~MISC_ENABLE_ENHANCED_SPEEDSTEP; msr_write(MSR_IA32_MISC_ENABLE, msr); } + +int cpu_get_coord_type(void) +{ + return HW_ALL; +} + +uint32_t cpu_get_min_ratio(void) +{ + msr_t msr; + /* Get bus ratio limits and calculate clock speeds */ + msr = msr_read(MSR_PLATFORM_INFO); + + return (msr.hi >> 8) & 0xff; /* Max Efficiency Ratio */ +} + +uint32_t cpu_get_max_ratio(void) +{ + u32 ratio_max; + msr_t msr; + + if (cpu_config_tdp_levels()) { + /* Set max ratio to nominal TDP ratio */ + msr = msr_read(MSR_CONFIG_TDP_NOMINAL); + ratio_max = msr.lo & 0xff; + } else { + msr = msr_read(MSR_PLATFORM_INFO); + /* Max Non-Turbo Ratio */ + ratio_max = (msr.lo >> 8) & 0xff; + } + return ratio_max; +} + +uint32_t cpu_get_bus_clock(void) +{ + /* CPU bus clock is set by default here to 100MHz. + * This function returns the bus clock in KHz. + */ + return INTEL_BCLK_MHZ * 1000; +} + +uint32_t cpu_get_power_max(void) +{ + msr_t msr; + int power_unit; + + msr = msr_read(MSR_PKG_POWER_SKU_UNIT); + power_unit = 2 << ((msr.lo & 0xf) - 1); + msr = msr_read(MSR_PKG_POWER_SKU); + return (msr.lo & 0x7fff) * 1000 / power_unit; +} + +uint32_t cpu_get_max_turbo_ratio(void) +{ + msr_t msr; + + msr = msr_read(MSR_TURBO_RATIO_LIMIT); + return msr.lo & 0xff; +} diff --git a/arch/x86/include/asm/cpu_common.h b/arch/x86/include/asm/cpu_common.h index cdd99a90b7..c3f699ffd3 100644 --- a/arch/x86/include/asm/cpu_common.h +++ b/arch/x86/include/asm/cpu_common.h @@ -128,4 +128,35 @@ void cpu_set_eist(bool eist_status); */ void cpu_set_p_state_to_turbo_ratio(void); +/* + * cpu_get_bus_clock returns the bus clock frequency in KHz. + * This is the value the clock ratio is multiplied with. + */ +uint32_t cpu_get_bus_clock(void); + +int cpu_get_coord_type(void); + +/* + * cpu_get_min_ratio returns the minimum frequency ratio that is supported + * by this processor + */ +uint32_t cpu_get_min_ratio(void); + +/* + * cpu_get_max_ratio returns the nominal TDP ratio if available or the + * maximum non turbo frequency ratio for this processor + */ +uint32_t cpu_get_max_ratio(void); + +/* + * cpu_get_power_max calculates CPU TDP in mW + */ +uint32_t cpu_get_power_max(void); + +/* + * cpu_get_max_turbo_ratio returns the maximum turbo ratio limit for the + * processor + */ +uint32_t cpu_get_max_turbo_ratio(void); + #endif