From patchwork Wed Sep 11 04:27:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983625 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SH504lkz1y1C for ; Wed, 11 Sep 2024 14:28:00 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExN-00041G-4n; Wed, 11 Sep 2024 04:27:53 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExK-0003yM-Nb for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:27:50 +0000 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 8D8253F12E for ; Wed, 11 Sep 2024 04:27:50 +0000 (UTC) Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-718f329aefdso3999920b3a.1 for ; Tue, 10 Sep 2024 21:27:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028868; x=1726633668; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KLnO/AgdF4K3ycVsmI8AGMphNpSZtBrCUK8XrB4ALkg=; b=kdh1wL0COak0kbrfBUwniOYOkgJFGDTFDyPTUcOcbsDglFCYjuiuSIIhqMMNJwoF2A 84fCPNuZDivAQX/5yN/kbMxEmojySIm7Xb5oj6sncwvxq33zINh0AyXAjWHDndPqugf6 iaCeFCPQOAY4V8/DE6uG8GK/MtVeJ3JPzGQRvWHiXgTvtoyjXjtU6ntIKxU33WJD+06C QqslZZXg1SKjfvigun72uyJE4HLKYsWIdB+6l3lCZTcgjgtdKFNl4/94dGfbdjw87jKA EEMU16Ha+z4Gjo3zY4v+sX8n6i6Vv0gREs0J6Cc9AKAspVquBqh3B+Bqi9QG1Wl4uGoG 9Ypw== X-Gm-Message-State: AOJu0YzOE4xy61/fVEV2elM6PYbpt8NKrvYdGE1RkaAiQ4sbxjpXYfFs jdBnWY7C2SS4LO2585rVS2TmSRbWcBf4rjRZev5U4h78JmOt0aLfKlLSnOBkBsm8hcR09+HEEWT BkgLJeI5Kw70WpEbhHP5wnoWxX7U+cZxPS5qrSyLwWWx14smMDVST6tvkU+urEj5cG1IE2e9x2H qDl/XWqLWn X-Received: by 2002:a05:6a21:4a4c:b0:1cc:dd02:f8f3 with SMTP id adf61e73a8af0-1cf5e106e2emr4571034637.28.1726028868569; Tue, 10 Sep 2024 21:27:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHi12OwpNa8+9SSk21SRDV8OT70HugmnVOa4pWfLLFqHfgNNxOqiUzayaJxcrE0n2t46JuV4g== X-Received: by 2002:a05:6a21:4a4c:b0:1cc:dd02:f8f3 with SMTP id adf61e73a8af0-1cf5e106e2emr4571005637.28.1726028868160; Tue, 10 Sep 2024 21:27:48 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d823cf3a6asm6421320a12.26.2024.09.10.21.27.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:27:47 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 05/17] ACPI: processor: Introduce acpi_processor_evaluate_cst() Date: Wed, 11 Sep 2024 01:27:14 -0300 Message-Id: <20240911042726.959018-6-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 In order to separate the ACPI _CST evaluation from checks specific to the ACPI processor driver, move the majority of the acpi_processor_get_power_info_cst() function body to a new function, acpi_processor_evaluate_cst(), that will extract the C-states information from _CST output, and redefine acpi_processor_get_power_info_cst() as a wrapper around it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki (cherry picked from commit 987c785319b99e32602f7f86cfae3cf9b81e402b) Signed-off-by: Marcelo Henrique Cerri --- drivers/acpi/processor_idle.c | 52 +++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 34cc23abd038..aca7c306f2cb 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -298,21 +298,17 @@ static int acpi_processor_get_power_info_default(struct acpi_processor *pr) return 0; } -static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) +static int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, + struct acpi_processor_power *info) { + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *cst; acpi_status status; u64 count; - int current_count; + int current_count = 0; int i, ret = 0; - struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; - union acpi_object *cst; - - if (nocst) - return -ENODEV; - current_count = 0; - - status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer); + status = acpi_evaluate_object(handle, "_CST", NULL, &buffer); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n")); return -ENODEV; @@ -336,9 +332,6 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) goto end; } - /* Tell driver that at least _CST is supported. */ - pr->flags.has_cst = 1; - for (i = 1; i <= count; i++) { union acpi_object *element; union acpi_object *obj; @@ -384,7 +377,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) cx.entry_method = ACPI_CSTATE_SYSTEMIO; if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { if (acpi_processor_ffh_cstate_probe - (pr->id, &cx, reg) == 0) { + (cpu, &cx, reg) == 0) { cx.entry_method = ACPI_CSTATE_FFH; } else if (cx.type == ACPI_STATE_C1) { /* @@ -433,7 +426,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) continue; current_count++; - memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx)); + memcpy(&info->states[current_count], &cx, sizeof(cx)); /* * We support total ACPI_PROCESSOR_MAX_POWER - 1 @@ -447,12 +440,9 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) } } - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d power states\n", - current_count)); + acpi_handle_info(handle, "Found %d idle states\n", current_count); - /* Validate number of power states discovered */ - if (current_count < 2) - ret = -EFAULT; + info->count = current_count; end: kfree(buffer.pointer); @@ -460,6 +450,28 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) return ret; } +static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) +{ + int ret; + + if (nocst) + return -ENODEV; + + ret = acpi_processor_evaluate_cst(pr->handle, pr->id, &pr->power); + if (ret) + return ret; + + /* + * It is expected that there will be at least 2 states, C1 and + * something else (C2 or C3), so fail if that is not the case. + */ + if (pr->power.count < 2) + return -EFAULT; + + pr->flags.has_cst = 1; + return 0; +} + static void acpi_processor_power_verify_c3(struct acpi_processor *pr, struct acpi_processor_cx *cx) {