Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1509486rdh; Mon, 25 Sep 2023 15:21:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgNcDnopMnAYL+WJuI7om1Rko/jTyXAY/QyRtY0u7smHK0VfMH0bsyWydkylhPwt29Sx7R X-Received: by 2002:a17:90a:dc0b:b0:277:61d7:78be with SMTP id i11-20020a17090adc0b00b0027761d778bemr1288032pjv.14.1695680503173; Mon, 25 Sep 2023 15:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695680503; cv=none; d=google.com; s=arc-20160816; b=ieAa0BImBjLkqgSayjhEs+Hv0MgbiwhqFPGNC1fYunYnbQxjcxjiWYKdpsuBvwk/Pc EkSdBU/2ryLff/FshtC1qGIxQe3/gApopq1dpc/3BQhXTzMHC9aTwS6F+wNo7/FPrQx+ 6AIDorydlMekZbiYdBMIXGIY62Q85yVocQeHKW0FALPDlxlVunPslk1MibljF7Ul8H5Q 3DV22pOsMiJ3d5rk80y/wF8djJOyGU8Iia/wqKGSlaC/snLgLqHgFPzvQaC6d/V85aln dko/XTQEK2+er8AFEVYWmlzGGu8Ae5S9JnPiO574tUCrvXf2f0AQUfg5abcXxmL2tyDJ tvnQ== 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:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id s70-20020a632c49000000b00578d460cd7esi11067559pgs.431.2023.09.25.15.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 15:21:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; 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:4 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 howler.vger.email (Postfix) with ESMTP id CBF6C811246D; Mon, 25 Sep 2023 11:06:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230184AbjIYSG1 (ORCPT + 99 others); Mon, 25 Sep 2023 14:06:27 -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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-17.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,SPF_HELO_PASS,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 11:06:33 -0700 (PDT) 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; -- 2.34.1