Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3203270rdb; Tue, 26 Dec 2023 22:28:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IElWigYLX26WJKrdDFQVZf8F2fjsexbnsDPHUtgak5ODr4003xJ36LZa6tZnrYE+Bee8hRm X-Received: by 2002:a17:90b:38cf:b0:28c:230d:d305 with SMTP id nn15-20020a17090b38cf00b0028c230dd305mr1449003pjb.40.1703658513657; Tue, 26 Dec 2023 22:28:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703658513; cv=none; d=google.com; s=arc-20160816; b=t9pOZ5As68VD9/UcoVpysNqaOxaRTM4kvqu63q3YGSd3loSLyZwzY0r+dNJluQHELJ lkZesXj/A2JyBu+1K39v+KZR9A8tmPpZvhCzbg5sui1g0C+d7D1ri5u/jzsOF0fyRcg0 9NO11Zf1ql/CugpcO+aF4dhpq1lrPr+SqVLHJK+zCJ2cpKmw4zcNjAfgVcy6iCTAKUMA 1hOtpzgnVO+ZDLvtRMgnxayTpK6/kCjd8SEylxknfl48RjZoi0EenZVM71fWnwvM6f5z fGqwXqTbXKTBa5HtKFYs7xAh3J9zHo7LsCJilqbIILeW15t0zuJfExVig2Gs5PEv24Sq TClg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=89VJADCunEvXfOporp9iJzyK3qs3okc7yjf+UwRwMNE=; fh=+uoRuePerzEUtGMtUkxhzXG+DZX8dBsFnLC2Ry+GNNY=; b=OU1MLsWxHi1jH91zYby+NLI6w6SOZt/j9a7EUJ+i1kFdR6okKpRUkuF8E/ybHJI1nO QKQ1qXkPTPzHIRzfd8FEhHpJkV6V2f19aY+tmY8/k/8CPhfcwRDUVUnpwsXgEpYTHi/Q UFaFtrZfS1Ak9vAlBOfGRsknf9tinyH1ypvMO8XXLhQ6p/DGy724AevYPvjoum5CrKeh iLWhNGmJTQLGSm6SkjLPrkJdpo7fuKLo7y7jyqyLDSEUQZA9yYc7XXWXtPKeaKTIvjtd oY9rerFR1PXWGtHy9+skDK16bKQtw8V49GNGgyYAaKWJk35LlDpEyxj4osIghLy168q/ fcGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WFQg8qCE; spf=pass (google.com: domain of linux-kernel+bounces-11859-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11859-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x6-20020a17090a970600b0028c395fbd01si6293899pjo.12.2023.12.26.22.28.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 22:28:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11859-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WFQg8qCE; spf=pass (google.com: domain of linux-kernel+bounces-11859-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11859-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 54B77283739 for ; Wed, 27 Dec 2023 06:28:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0127063B6; Wed, 27 Dec 2023 06:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WFQg8qCE" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39FC0522C; Wed, 27 Dec 2023 06:28:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703658483; x=1735194483; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=3J1rY7OAYKzRe6JNvKbC7Xa6ZAlF+WUnw25g4mgFxQs=; b=WFQg8qCEtvzvZin0y7l6P4rvFS/nYTbxnuk8AQmolrcJr7t7Ruu4lsCh 6YpW1A+//vMh1TERv0FwQbw1YVN+g690kVbDafnKZqJaxt4E6T20unJ2/ K+c8bQkeeHlMMbcdn/nQMiCLvtu7ZizdC5OuFizMlgEDqbBNDYw6/b/Jl VCQrlLnuRlEyMzLwtOdqdhRESabkkIVLZcV+ZJMni1so28BAkD0bDzF3i 3YcBe7ko5MaYoHVcC0xnt4u89Fybug9gaSZpK7SNJc0QFD2YWbljQ3xjY Qq3zs1LniQM04D2kRd4PFZceOFpd9uzwUwt4lETsR08gZgXmk+qHNFhBw A==; X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="427584072" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="427584072" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2023 22:28:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="1025316082" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="1025316082" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by fmsmga006.fm.intel.com with ESMTP; 26 Dec 2023 22:28:00 -0800 From: Ricardo Neri To: "Rafael J. Wysocki" Cc: Chen Yu , Len Brown , Srinivas Pandruvada , Stanislaw Gruszka , Zhang Rui , Zhao Liu , stable@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Neri , Zhao Liu Subject: [PATCH 1/4] thermal: intel: hfi: Refactor enabling code into helper functions Date: Tue, 26 Dec 2023 22:29:37 -0800 Message-Id: <20231227062940.10780-2-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231227062940.10780-1-ricardo.neri-calderon@linux.intel.com> References: <20231227062940.10780-1-ricardo.neri-calderon@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: In preparation to add a suspend notifier, wrap the logic to enable HFI and program its memory buffer into helper functions. Both the CPU hotplug callback and the suspend notifier will use it. Cc: Chen Yu Cc: Len Brown Cc: Srinivas Pandruvada Cc: Stanislaw Gruszka Cc: Zhang Rui Cc: Zhao Liu Cc: linux-pm@vger.kernel.org Cc: stable@vger.kernel.org Signed-off-by: Ricardo Neri --- drivers/thermal/intel/intel_hfi.c | 46 +++++++++++++++++-------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c index c69db6c90869..87ac7b196981 100644 --- a/drivers/thermal/intel/intel_hfi.c +++ b/drivers/thermal/intel/intel_hfi.c @@ -347,6 +347,25 @@ static void init_hfi_instance(struct hfi_instance *hfi_instance) hfi_instance->data = hfi_instance->hdr + hfi_features.hdr_size; } +static void hfi_enable(void) +{ + u64 msr_val; + + rdmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val); + msr_val |= HW_FEEDBACK_CONFIG_HFI_ENABLE_BIT; + wrmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val); +} + +static void hfi_set_hw_table(struct hfi_instance *hfi_instance) +{ + phys_addr_t hw_table_pa; + u64 msr_val; + + hw_table_pa = virt_to_phys(hfi_instance->hw_table); + msr_val = hw_table_pa | HW_FEEDBACK_PTR_VALID_BIT; + wrmsrl(MSR_IA32_HW_FEEDBACK_PTR, msr_val); +} + /** * intel_hfi_online() - Enable HFI on @cpu * @cpu: CPU in which the HFI will be enabled @@ -364,8 +383,6 @@ void intel_hfi_online(unsigned int cpu) { struct hfi_instance *hfi_instance; struct hfi_cpu_info *info; - phys_addr_t hw_table_pa; - u64 msr_val; u16 die_id; /* Nothing to do if hfi_instances are missing. */ @@ -403,14 +420,16 @@ void intel_hfi_online(unsigned int cpu) /* * Hardware is programmed with the physical address of the first page * frame of the table. Hence, the allocated memory must be page-aligned. + * + * Some processors do not forget the initial address of the HFI table + * even after having been reprogrammed. Keep using the same pages. Do + * not free them. */ hfi_instance->hw_table = alloc_pages_exact(hfi_features.nr_table_pages, GFP_KERNEL | __GFP_ZERO); if (!hfi_instance->hw_table) goto unlock; - hw_table_pa = virt_to_phys(hfi_instance->hw_table); - /* * Allocate memory to keep a local copy of the table that * hardware generates. @@ -420,16 +439,6 @@ void intel_hfi_online(unsigned int cpu) if (!hfi_instance->local_table) goto free_hw_table; - /* - * Program the address of the feedback table of this die/package. On - * some processors, hardware remembers the old address of the HFI table - * even after having been reprogrammed and re-enabled. Thus, do not free - * the pages allocated for the table or reprogram the hardware with a - * new base address. Namely, program the hardware only once. - */ - msr_val = hw_table_pa | HW_FEEDBACK_PTR_VALID_BIT; - wrmsrl(MSR_IA32_HW_FEEDBACK_PTR, msr_val); - init_hfi_instance(hfi_instance); INIT_DELAYED_WORK(&hfi_instance->update_work, hfi_update_work_fn); @@ -438,13 +447,8 @@ void intel_hfi_online(unsigned int cpu) cpumask_set_cpu(cpu, hfi_instance->cpus); - /* - * Enable the hardware feedback interface and never disable it. See - * comment on programming the address of the table. - */ - rdmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val); - msr_val |= HW_FEEDBACK_CONFIG_HFI_ENABLE_BIT; - wrmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val); + hfi_set_hw_table(hfi_instance); + hfi_enable(); unlock: mutex_unlock(&hfi_instance_lock); -- 2.25.1