From patchwork Mon Sep 25 18:05:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarred White X-Patchwork-Id: 144638 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1566070vqu; Mon, 25 Sep 2023 16:57:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/xCCw4yHnQFUMefHrAnVNf85B0iZIK9bw5WcfBwGPKUl5+MoO65wElGP8f/Yfd5QT3QOJ X-Received: by 2002:a05:6a21:3290:b0:15d:8eea:27a3 with SMTP id yt16-20020a056a21329000b0015d8eea27a3mr1652010pzb.3.1695686223952; Mon, 25 Sep 2023 16:57:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695686223; cv=none; d=google.com; s=arc-20160816; b=jSUMlG4+2uvmQm/EcJrh4+PBKwwXjBE9NtvOGwtlp37Gu+mVV7w8br3LbCBQfF1YKA AsMp0ywMInwOvPHJPYDkGo2Iq0XnfC3MPOnrZlGbRPZkfRGLhxsgEBCp6Zhm5jn0jXrB EA30a59YcyxIv3Zch88vEuPRyoj/TmFtheSiZ7MJuk3BayOGMJsRdO9wkyu6oe+3Xb8y nW149pjOt27WkbqFwymXWC0gJOBIKZ1qCI8ky7lFhIg0YtXVSUE005GXdJibt+BXglI+ uJ73nXUHPqNngQ1tXahKobypD/U4k2KCqIgROouxLfYreFwuIjdNTWSsID3HnA1Au8bf H4/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature:dkim-filter; bh=p14Nn8yShFD3PfmnLpi1+w5sDpk1yljf0ug3OMUAn1A=; fh=0xbtPLRU53/wDmHMVyhvQbgZr4AriaKEuH8oz0aUKDA=; b=pkA4T70Rn4yj/lUKO8EpJMUzGpKckdDOtf/6ZKYc2GLCCK8t46zl60OL2Es4vcQz+h hCyQ3y9Lkri3ie+GuOZtA5/aHI0FFmHHKR3uOtjE1q918c08iUKoZPdZkupUVKqXRTrt U+hlYkVLvCrCBH+4TD49F8tpeCbwec0ZCQhNkPJ/riWwYcLzTNlLR6eZ0NbOyb1pyKrV 11KtJnULR14ZyTxAAa7PfQXtT6Ro0hxUxWBbhHqE/gQr34gZbqiUuH1zyVzTsl4lamjA kTNS01kxdOxyFEiD/owsHTkzMRbTcrY4zHqXbLXPDidukGXQewWICUR5Fhj04mikOFER 4jPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=aYiDuMSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id t185-20020a6381c2000000b005697ed9a47csi10582827pgd.29.2023.09.25.16.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 16:57:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=aYiDuMSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id E905180FCE1D; Mon, 25 Sep 2023 11:06:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230415AbjIYSG2 (ORCPT + 29 others); Mon, 25 Sep 2023 14:06:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbjIYSG0 (ORCPT ); Mon, 25 Sep 2023 14:06:26 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7E4C210C; Mon, 25 Sep 2023 11:06:17 -0700 (PDT) Received: from localhost.localdomain (unknown [167.220.81.210]) by linux.microsoft.com (Postfix) with ESMTPSA id C1BC1212C816; Mon, 25 Sep 2023 11:06:16 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C1BC1212C816 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1695665176; bh=p14Nn8yShFD3PfmnLpi1+w5sDpk1yljf0ug3OMUAn1A=; h=From:To:Subject:Date:From; b=aYiDuMSiNfoqP1ABMbBcdZ++MtF6+932VxIdLt8NPUWFwI0NqurbgHc0dOFr6h1nz vjeT21O0jYE2Agwul0i8dRPtNgd3O8wC/xO0I6GG6gnJ5BQX5rllfGvZesNZwHqG43 yH7M126uFcTaVUIciQeaIsPaSHpW7y+pfFksFMFs= From: Jarred White To: "Rafael J. Wysocki" , Len Brown , linux-acpi@vger.kernel.org (open list:ACPI), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] acpi: Use access_width over register_width for system memory accesses Date: Mon, 25 Sep 2023 11:05:52 -0700 Message-Id: <20230925180552.76071-1-jarredwhite@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 25 Sep 2023 11:06:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778055878129392206 X-GMAIL-MSGID: 1778055878129392206 To align with ACPI 6.3+, since bit_width can be any 8-bit value, we cannot depend on it being always on a clean 8b boundary. Instead, use access_width to determine the size and use the offset and width to shift and mask the bit swe want to read/write out. Make sure to add a check for system memory since pcc redefines the access_width to subspace id. Signed-off-by: Jarred White --- drivers/acpi/cppc_acpi.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 7ff269a78c20..07619b36c056 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -777,6 +777,7 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) } else if (gas_t->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { if (gas_t->address) { void __iomem *addr; + size_t access_width; if (!osc_cpc_flexible_adr_space_confirmed) { pr_debug("Flexible address space capability not supported\n"); @@ -784,7 +785,8 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) goto out_free; } - addr = ioremap(gas_t->address, gas_t->bit_width/8); + access_width = ((8 << (gas_t->access_width - 1)) / 8); + addr = ioremap(gas_t->address, access_width); if (!addr) goto out_free; cpc_ptr->cpc_regs[i-2].sys_mem_vaddr = addr; @@ -980,6 +982,7 @@ int __weak cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val) static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val) { void __iomem *vaddr = NULL; + int size; int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu); struct cpc_reg *reg = ®_res->cpc_entry.reg; @@ -1015,7 +1018,12 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val) return acpi_os_read_memory((acpi_physical_address)reg->address, val, reg->bit_width); - switch (reg->bit_width) { + if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) + size = (8 << (reg->access_width - 1)); + else + size = reg->bit_width; + + switch (size) { case 8: *val = readb_relaxed(vaddr); break; @@ -1034,12 +1042,16 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val) return -EFAULT; } + if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) + *val = (*val >> reg->bit_offset) & GENMASK((reg->bit_width) - 1, 0); + return 0; } static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val) { int ret_val = 0; + int size; void __iomem *vaddr = NULL; int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu); struct cpc_reg *reg = ®_res->cpc_entry.reg; @@ -1067,7 +1079,13 @@ static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val) return acpi_os_write_memory((acpi_physical_address)reg->address, val, reg->bit_width); - switch (reg->bit_width) { + if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { + size = (8 << (reg->access_width - 1)); + val = (val >> reg->bit_offset) & GENMASK((reg->bit_width) - 1, 0); + } else + size = reg->bit_width; + + switch (size) { case 8: writeb_relaxed(val, vaddr); break;