Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp732134rdh; Thu, 26 Oct 2023 14:15:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH4ZIjvMh8Vg5/N5jDV1gO+pJ03BTmxR/XONzO/1ar4Ss7o32HG/9/TKoKYoBaWKNJooM5n X-Received: by 2002:a05:6358:338b:b0:168:f4a8:8ad7 with SMTP id i11-20020a056358338b00b00168f4a88ad7mr1221170rwd.27.1698354956214; Thu, 26 Oct 2023 14:15:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698354956; cv=none; d=google.com; s=arc-20160816; b=ptoQnNpoDUkkc8+Wh3XICv0O+6wwXdj25NqunLabkfEhh1Jpw+c1ExgJWGPDhfpQG5 pdxbD6WKLyCy4sBJMr3kKFEKntQQ04PU8oU9pyT2KjCJKl0eIiqJt9P30LoW0ZDih8IB fzAJSJjyFNjblBPfFA6pZ3MHHfQV8rGNmcFcBkm6yi6Jz0u7IhebIm0O79HG63eSd+8J 3FfZnsxQRDdxo4bwTx15HgWjrRf5OVbhqCXGu1bVOsVFy0TZ4S8+C1kDbSqwHJBwKi9i o6vjWMcCbTDvJxZ9hYe0bsmh89Ww09iCunjQW70R9WeshOVRDh+AGJ7/vJC7HunjITMq zDLQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=PgZoaoibE13ScmHye43oCQ/2BwAjMAKb/hl5ibbfSWM=; fh=BXtardbZ3lhvSs79AzzpmUu34bhU9KbrTKiQHOMC6Pw=; b=jeNSTnuWL9J8mg8O1NXAL/4zBg597SuuaD2tDq9ZORsqXfcRqc3wTqCQ/M4yWl232o ydYQdWsAjD1sIBlG3KjinEL4oXc8I+IeJzkpNC1grWK3GSRwVkvbS6UmQx0EN6dsrzLF hMaMlhFIAxZgKdZ8hFMrumdWe5PRVTw3RrAqRM4i1piwaJzy1zQ5pGNBiC4byldGqzeM 3HuTzItk/K0SGYE5QsYc9aJ2pvFBrwmQFwqa0QrFaPezpeiAbWNsXXgna9zKjgBBum0h /yMfXy8qJ77i2Oqzlimmc9QBdZF2TY0TqtIZIFoZbEcQrqZXCMLp+UIYehNA+7JX86Q1 MS5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=mECLMyoq; 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 g19-20020a81fd13000000b0058c99180384si250974ywn.440.2023.10.26.14.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 14:15:56 -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=mECLMyoq; 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 C1A76801B99F; Thu, 26 Oct 2023 14:15:52 -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 S232171AbjJZVPn (ORCPT + 99 others); Thu, 26 Oct 2023 17:15:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232063AbjJZVPl (ORCPT ); Thu, 26 Oct 2023 17:15:41 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 76BA2D42; Thu, 26 Oct 2023 14:15:39 -0700 (PDT) Received: from localhost.localdomain (unknown [167.220.81.210]) by linux.microsoft.com (Postfix) with ESMTPSA id C581420B74C0; Thu, 26 Oct 2023 14:15:38 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C581420B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1698354938; bh=PgZoaoibE13ScmHye43oCQ/2BwAjMAKb/hl5ibbfSWM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mECLMyoqF9w2yNqUDNY7F9NDbH4P1tPk+cINv6d/rbddrJ7V/Sc9whevItpN7mq+d u0UwQDmnBKziulz0MoFpI9it8oTJ2Uv85lONKfus6VskyJEGvdYzT+1Pg+N2i1RnfH MSMwznr4M0zr0U1EEfpcVosP+E/DFd/TzQ0o3jhY= From: Jarred White To: jarredwhite@linux.microsoft.com Cc: lenb@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, rafael@kernel.org Subject: [PATCH v2] acpi: Use access_width over register_width for system memory accesses Date: Thu, 26 Oct 2023 14:15:13 -0700 Message-Id: <20231026211513.474-1-jarredwhite@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <42a5c36d-8b65-418f-9826-2808ab49d67a@linux.microsoft.com> References: <42a5c36d-8b65-418f-9826-2808ab49d67a@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 26 Oct 2023 14:15:52 -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 bits we 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 --- changelog: v1-->v2: 1. Fixed coding style errors 2. Backwards compatibility with ioremapping of address still an open question. Suggestions are welcomed. drivers/acpi/cppc_acpi.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 7ff269a78c20..fb37e1727bf8 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -163,6 +163,13 @@ show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, nominal_freq); show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, reference_perf); show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time); +/* Use access_width to determine the total number of bits */ +#define ACCESS_WIDTH_TO_BITS(reg) 8 << ((reg)->access_width - 1) + +/* Shift and apply the mask for CPC reads/writes */ +#define MASK_VAL(val) (((val) >> reg->bit_offset) & \ + GENMASK((reg->bit_width), 0)) + static ssize_t show_feedback_ctrs(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -777,6 +784,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 +792,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 = ACCESS_WIDTH_TO_BITS(gas_t) / 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 +989,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; @@ -991,7 +1001,7 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val) *val = 0; if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { - u32 width = 8 << (reg->access_width - 1); + u32 width = ACCESS_WIDTH_TO_BITS(reg); u32 val_u32; acpi_status status; @@ -1015,7 +1025,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 = ACCESS_WIDTH_TO_BITS(reg); + else + size = reg->bit_width; + + switch (size) { case 8: *val = readb_relaxed(vaddr); break; @@ -1034,18 +1049,22 @@ 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 = MASK_VAL(*val); + 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; if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { - u32 width = 8 << (reg->access_width - 1); + u32 width = ACCESS_WIDTH_TO_BITS(reg); acpi_status status; status = acpi_os_write_port((acpi_io_address)reg->address, @@ -1067,7 +1086,14 @@ 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 = ACCESS_WIDTH_TO_BITS(reg); + val = MASK_VAL(val); + } else { + size = reg->bit_width; + } + + switch (size) { case 8: writeb_relaxed(val, vaddr); break; -- 2.34.1