Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp601808ybl; Fri, 13 Dec 2019 01:28:39 -0800 (PST) X-Google-Smtp-Source: APXvYqxU2AQSUNP7mHUGYvAEVFgbe8ocPfxbCvGJW6aYwOOj/rnYjYwpfacxfjlF5eW4zxr4wHTK X-Received: by 2002:a05:6830:1d59:: with SMTP id p25mr14136226oth.308.1576229318931; Fri, 13 Dec 2019 01:28:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576229318; cv=none; d=google.com; s=arc-20160816; b=t3PYmxO+df3peQ7LKvasRhQ9lo6kqc1oVs3nnwUAgdQ/7G+gtYq1Eu/gkTkTRua2B5 FmF81bfdy/fVUDbKek23wwahWP3wV6w1SDhZdIJ74G4/IE5CKxleTagjFV9mgCJ2hOs4 o5lMSzox5Nkq39NL7ywsTCfMMMgxHv5dMEcVNRGVC0OJi/dSF2Qqn43YhDz0Fx+6Y3vM D/p2tJk59XzBXzrwDQdYKFsOx2iAPi6fraYpjeCZIuvo4Jm+/C9I/1oM5boS9XqCC/N2 HjmI5uFB5Fa0MESvK85ZdVLY5E+LGAHmvM3GUhzizo4t0ACdMtVI05KUIXPX6NR6i+OG ZU5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3lPynOKk+myjPRJXBlZGRnwFWwCJS41OREt+oz1sRA0=; b=rN55C8V06XFdlebOHKwnOJMA/G4sYcV0ZrZPVN+g/Ru3uX7NBeevVsWdA3ARPPD/uT ebPQ4/FYgXsORpi4kzshQ7uWif12cC9xMTHY28HDYv1GceLN1YBUVimuBnQbK5bDlDox adYXkuH4TFXpR+OhZ3AN4oG59h8v4GvmONPAldfDO7oZDAAy+Rbfoq6mhcWtGACuSWT0 7sP8II+ZMtRe6PNYJ/025awsnCl8PLPwogo4/FiwsOCM4QbSLGqa06WJ0gfHJMKzhjBy 3dq2rnZakXvagVDsVsFAw6OR1iUb+UzdgRXwJlE00FMfaqFbxIHHNTGybWYiTr2b4oSe aNGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i12si5307402otk.215.2019.12.13.01.28.27; Fri, 13 Dec 2019 01:28:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726823AbfLMJ1j (ORCPT + 99 others); Fri, 13 Dec 2019 04:27:39 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:45277 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726750AbfLMJ1g (ORCPT ); Fri, 13 Dec 2019 04:27:36 -0500 Received: from 79.184.255.82.ipv4.supernova.orange.pl (79.184.255.82) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.320) id dd2c8e29df03ce37; Fri, 13 Dec 2019 10:27:33 +0100 From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Len Brown , Srinivas Pandruvada , Len Brown Subject: [PATCH v1 03/10] ACPI: processor: Clean up acpi_processor_evaluate_cst() Date: Fri, 13 Dec 2019 10:14:46 +0100 Message-ID: <2158277.Sk0T0YLvXj@kreacher> In-Reply-To: <3950312.2WmFeOdZGY@kreacher> References: <3950312.2WmFeOdZGY@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Rafael J. Wysocki" Clean up acpi_processor_evaluate_cst() in multiple ways: * Rename current_count to last_index which matches the purpose of the variable better. * Consistently use acpi_handle_*() for printing messages and make the messages cleaner. * Drop redundant parens and braces. * Rewrite and clarify comments. * Rearrange checks and drop the redundant ones. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- No changes from the RFC version. --- drivers/acpi/processor_idle.c | 114 +++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 62 deletions(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index e92d0e6d4cd1..7c2fe3b2ec31 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -304,29 +304,29 @@ static int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, union acpi_object *cst; acpi_status status; u64 count; - int current_count = 0; + int last_index = 0; int i, ret = 0; status = acpi_evaluate_object(handle, "_CST", NULL, &buffer); if (ACPI_FAILURE(status)) { - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n")); + acpi_handle_debug(handle, "No _CST\n"); return -ENODEV; } cst = buffer.pointer; - /* There must be at least 2 elements */ - if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) { - pr_err("not enough elements in _CST\n"); + /* There must be at least 2 elements. */ + if (!cst || cst->type != ACPI_TYPE_PACKAGE || cst->package.count < 2) { + acpi_handle_warn(handle, "Invalid _CST output\n"); ret = -EFAULT; goto end; } count = cst->package.elements[0].integer.value; - /* Validate number of power states. */ + /* Validate the number of C-states. */ if (count < 1 || count != cst->package.count - 1) { - pr_err("count given by _CST is not valid\n"); + acpi_handle_warn(handle, "Inconsistent _CST data\n"); ret = -EFAULT; goto end; } @@ -337,111 +337,101 @@ static int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, struct acpi_power_register *reg; struct acpi_processor_cx cx; + /* + * If there is not enough space for all C-states, skip the + * excess ones and log a warning. + */ + if (last_index >= ACPI_PROCESSOR_MAX_POWER - 1) { + acpi_handle_warn(handle, + "No room for more idle states (limit: %d)\n", + ACPI_PROCESSOR_MAX_POWER - 1); + break; + } + memset(&cx, 0, sizeof(cx)); - element = &(cst->package.elements[i]); + element = &cst->package.elements[i]; if (element->type != ACPI_TYPE_PACKAGE) continue; if (element->package.count != 4) continue; - obj = &(element->package.elements[0]); + obj = &element->package.elements[0]; if (obj->type != ACPI_TYPE_BUFFER) continue; reg = (struct acpi_power_register *)obj->buffer.pointer; - if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO && - (reg->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) - continue; - - /* There should be an easy way to extract an integer... */ - obj = &(element->package.elements[1]); + obj = &element->package.elements[1]; if (obj->type != ACPI_TYPE_INTEGER) continue; cx.type = obj->integer.value; /* - * Some buggy BIOSes won't list C1 in _CST - - * Let acpi_processor_get_power_info_default() handle them later + * There are known cases in which the _CST output does not + * contain C1, so if the type of the first state found is not + * C1, leave an empty slot for C1 to be filled in later. */ if (i == 1 && cx.type != ACPI_STATE_C1) - current_count++; + last_index = 1; cx.address = reg->address; - cx.index = current_count + 1; + cx.index = last_index + 1; - cx.entry_method = ACPI_CSTATE_SYSTEMIO; if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { - if (acpi_processor_ffh_cstate_probe - (cpu, &cx, reg) == 0) { - cx.entry_method = ACPI_CSTATE_FFH; + if (!acpi_processor_ffh_cstate_probe(cpu, &cx, reg)) { + /* + * In the majority of cases _CST describes C1 as + * a FIXED_HARDWARE C-state, but if the command + * line forbids using MWAIT, use CSTATE_HALT for + * C1 regardless. + */ + if (cx.type == ACPI_STATE_C1 && + boot_option_idle_override == IDLE_NOMWAIT) { + cx.entry_method = ACPI_CSTATE_HALT; + snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); + } else { + cx.entry_method = ACPI_CSTATE_FFH; + } } else if (cx.type == ACPI_STATE_C1) { /* - * C1 is a special case where FIXED_HARDWARE - * can be handled in non-MWAIT way as well. - * In that case, save this _CST entry info. - * Otherwise, ignore this info and continue. + * In the special case of C1, FIXED_HARDWARE can + * be handled by executing the HLT instruction. */ cx.entry_method = ACPI_CSTATE_HALT; snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); } else { continue; } - if (cx.type == ACPI_STATE_C1 && - (boot_option_idle_override == IDLE_NOMWAIT)) { - /* - * In most cases the C1 space_id obtained from - * _CST object is FIXED_HARDWARE access mode. - * But when the option of idle=halt is added, - * the entry_method type should be changed from - * CSTATE_FFH to CSTATE_HALT. - * When the option of idle=nomwait is added, - * the C1 entry_method type should be - * CSTATE_HALT. - */ - cx.entry_method = ACPI_CSTATE_HALT; - snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); - } - } else { + } else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { + cx.entry_method = ACPI_CSTATE_SYSTEMIO; snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x", cx.address); + } else { + continue; } - if (cx.type == ACPI_STATE_C1) { + if (cx.type == ACPI_STATE_C1) cx.valid = 1; - } - obj = &(element->package.elements[2]); + obj = &element->package.elements[2]; if (obj->type != ACPI_TYPE_INTEGER) continue; cx.latency = obj->integer.value; - obj = &(element->package.elements[3]); + obj = &element->package.elements[3]; if (obj->type != ACPI_TYPE_INTEGER) continue; - current_count++; - memcpy(&info->states[current_count], &cx, sizeof(cx)); - - /* - * We support total ACPI_PROCESSOR_MAX_POWER - 1 - * (From 1 through ACPI_PROCESSOR_MAX_POWER - 1) - */ - if (current_count >= (ACPI_PROCESSOR_MAX_POWER - 1)) { - pr_warn("Limiting number of power states to max (%d)\n", - ACPI_PROCESSOR_MAX_POWER); - pr_warn("Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n"); - break; - } + memcpy(&info->states[++last_index], &cx, sizeof(cx)); } - acpi_handle_info(handle, "Found %d idle states\n", current_count); + acpi_handle_info(handle, "Found %d idle states\n", last_index); - info->count = current_count; + info->count = last_index; end: kfree(buffer.pointer); -- 2.16.4