From patchwork Tue Jun 20 23:01:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 110708 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3996210vqr; Tue, 20 Jun 2023 16:12:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Fa0Z9PcszrJACzWaUsisCcAXenht/SiiCWHe0kA9D9wpzyir9leRJbla62o9+gr5lu4bm X-Received: by 2002:a17:902:ed49:b0:1b2:1942:9106 with SMTP id y9-20020a170902ed4900b001b219429106mr7803355plb.64.1687302744462; Tue, 20 Jun 2023 16:12:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687302744; cv=none; d=google.com; s=arc-20160816; b=rpsMwytZmZamjaclaeLBYHVIRayLkkC9ZMuVEvxz3eDyCUODpIiZEbKr7UfF8nr+un NgqO0Io7QcVvgPjOWdJpDXuK/2GfYAu4PHwi2POxTdGAeurVWF6DdY0XM3yweXxUqnZd WO5kqpnOYyQDxz3uhOVkV5DqQU1Kp+Yn9Fg9tHaX2oavW5+oOz58M+JB5Ao7/Hw5mGzM itvLsLI1babe5Em1QEm4KSQIdJ1jvWA9YQO9TN9/6UGEIM6EWphIPmG2qnFkJp7FPdjE Dr21ISNJHUSoOjH8MRhMHya5ekQh/k7lEe54cGjwn57RejBC48dKVkPfThNlfZ1AFszS Lc2g== 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; bh=TKlctW9yC9sItpozQdpc9a/IhJjPb+Pu6Qb4AzHT1Kw=; b=c0GdlOTHSFMwKEEkkB+u9Pm+SVKrVJ1cIn6+s1MEhjSSFVhnsIs/J2d+TgF0HVOshr ZMWoMUnWz/LpsoAPzgmBAx4sG9OxfVlYSIRQY4BhK2/qdozkBEqZZgHeiZQXHdaE+0gJ seah2O4GP11aj84s3X2bpF+zk2jk9XY/7LUgQfCqHsbpkWKjaBpr1/TEbORAX6/nbuqD nEJconwdBqvTrwpAwU2rfYrxQMSJtYwgjBFpgGktBDzFxvojKbxbCiH2tg7e9KVr8z1z YWkVFCAaRfgfouDOOwaQ5grtSyEfcdqUGOqQHnSEHEjGXMHLSMeE0ps0DrHsxI+mJovp GpCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=U66D3E1J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b18-20020a170902d89200b001ab06251f98si2738848plz.429.2023.06.20.16.12.09; Tue, 20 Jun 2023 16:12:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=U66D3E1J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230047AbjFTXCH (ORCPT + 99 others); Tue, 20 Jun 2023 19:02:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbjFTXBz (ORCPT ); Tue, 20 Jun 2023 19:01:55 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3EC31A8; Tue, 20 Jun 2023 16:01:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687302113; x=1718838113; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gGpDiM9bWj9bntYZQruCdvhXBOOoc52WSEV/glzF/vQ=; b=U66D3E1J6aARG5nO2ZvFAyjmHzkr2bz7TD98D3fA8gXI/HjaEVQNLpvL 90B2xS1WQsWFjFKA9MJ973lbjWvDd80pvXWy/vtfFtkPoJnL5zc/STNr8 O3WzbUvS/5rd6uRapmvo16MfUTS7ZJxRmttpXRrHIIZsns2UdRtAsHwvs 5S/dq/+segZRDWJxCxpMDph3KjX2IsjWuD8UCEaTvV/PfzBDBZ7Qt8UHs TbWKs5y1Ac9DhhjreWgnynOj4kQ9XOkd73XJROmQvIy6GCO/6PVcMpZG7 5IziW1GsA5pX/J55FW44UVk/PKjPcn9Yl+DKV0noMmxzb9h9HTquZnMFx A==; X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="340347272" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="340347272" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 16:01:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="1044465309" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="1044465309" Received: from spandruv-desk.jf.intel.com ([10.54.75.8]) by fmsmga005.fm.intel.com with ESMTP; 20 Jun 2023 16:01:52 -0700 From: Srinivas Pandruvada To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH 1/7] thermal: int340x: processor_thermal: Move mailbox code to common module Date: Tue, 20 Jun 2023 16:01:44 -0700 Message-Id: <20230620230150.3068704-2-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> References: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769265162426953066?= X-GMAIL-MSGID: =?utf-8?q?1769265162426953066?= The processor thermal mailbox is used for workload type request and also in the processor thermal RFIM module. So, move the workload type request code to its own module from the current processor thermal mailbox module. processor_thermal_mailbox.c contains only mailbox read/write related source code. The source related to workload_types requests is moved to a module processor_thermal_wlt_req.c. In addition -Rename PROC_THERMAL_FEATURE_MBOX to PROC_THERMAL_FEATURE_WLT_REQ. - proc_thermal_mbox_add(), which adds workload type sysfs attribute group is renamed to proc_thermal_wlt_req_add(). -proc_thermal_mbox_remove() is renamed to proc_thermal_wlt_req_remove(). While here, resolve check patch warnings for 100 columns for only modified lines. No functional changes are expected. Signed-off-by: Srinivas Pandruvada Reviewed-by: Zhang Rui --- .../thermal/intel/int340x_thermal/Makefile | 1 + .../processor_thermal_device.c | 8 +- .../processor_thermal_device.h | 12 +- .../processor_thermal_device_pci.c | 10 +- .../processor_thermal_device_pci_legacy.c | 3 +- .../int340x_thermal/processor_thermal_mbox.c | 130 ----------------- .../processor_thermal_wlt_req.c | 137 ++++++++++++++++++ 7 files changed, 160 insertions(+), 141 deletions(-) create mode 100644 drivers/thermal/intel/int340x_thermal/processor_thermal_wlt_req.c diff --git a/drivers/thermal/intel/int340x_thermal/Makefile b/drivers/thermal/intel/int340x_thermal/Makefile index 4e852ce4a5d5..76e053e541f0 100644 --- a/drivers/thermal/intel/int340x_thermal/Makefile +++ b/drivers/thermal/intel/int340x_thermal/Makefile @@ -10,5 +10,6 @@ obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_device_pci.o obj-$(CONFIG_PROC_THERMAL_MMIO_RAPL) += processor_thermal_rapl.o obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_rfim.o obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_mbox.o +obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_wlt_req.o obj-$(CONFIG_INT3406_THERMAL) += int3406_thermal.o obj-$(CONFIG_ACPI_THERMAL_REL) += acpi_thermal_rel.o diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c index 3ca0a2f5937f..48f6c72b05f6 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c @@ -346,8 +346,8 @@ int proc_thermal_mmio_add(struct pci_dev *pdev, } } - if (feature_mask & PROC_THERMAL_FEATURE_MBOX) { - ret = proc_thermal_mbox_add(pdev, proc_priv); + if (feature_mask & PROC_THERMAL_FEATURE_WLT_REQ) { + ret = proc_thermal_wlt_req_add(pdev, proc_priv); if (ret) { dev_err(&pdev->dev, "failed to add MBOX interface\n"); goto err_rem_rfim; @@ -374,8 +374,8 @@ void proc_thermal_mmio_remove(struct pci_dev *pdev, struct proc_thermal_device * proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_DVFS) proc_thermal_rfim_remove(pdev); - if (proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_MBOX) - proc_thermal_mbox_remove(pdev); + if (proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_WLT_REQ) + proc_thermal_wlt_req_remove(pdev); } EXPORT_SYMBOL_GPL(proc_thermal_mmio_remove); diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h index 7acaa8f1b896..7cdeca2edc21 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h @@ -59,7 +59,7 @@ struct rapl_mmio_regs { #define PROC_THERMAL_FEATURE_RAPL 0x01 #define PROC_THERMAL_FEATURE_FIVR 0x02 #define PROC_THERMAL_FEATURE_DVFS 0x04 -#define PROC_THERMAL_FEATURE_MBOX 0x08 +#define PROC_THERMAL_FEATURE_WLT_REQ 0x08 #define PROC_THERMAL_FEATURE_DLVR 0x10 #if IS_ENABLED(CONFIG_PROC_THERMAL_MMIO_RAPL) @@ -80,8 +80,14 @@ static void __maybe_unused proc_thermal_rapl_remove(void) int proc_thermal_rfim_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv); void proc_thermal_rfim_remove(struct pci_dev *pdev); -int proc_thermal_mbox_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv); -void proc_thermal_mbox_remove(struct pci_dev *pdev); +int proc_thermal_wlt_req_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv); +void proc_thermal_wlt_req_remove(struct pci_dev *pdev); + +#define MBOX_CMD_WORKLOAD_TYPE_READ 0x0E +#define MBOX_CMD_WORKLOAD_TYPE_WRITE 0x0F + +#define MBOX_DATA_BIT_AC_DC 30 +#define MBOX_DATA_BIT_VALID 31 int processor_thermal_send_mbox_read_cmd(struct pci_dev *pdev, u16 id, u64 *resp); int processor_thermal_send_mbox_write_cmd(struct pci_dev *pdev, u16 id, u32 data); diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c index 0d1e98007270..5a2bcfff0a68 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c @@ -350,9 +350,13 @@ static SIMPLE_DEV_PM_OPS(proc_thermal_pci_pm, proc_thermal_pci_suspend, proc_thermal_pci_resume); static const struct pci_device_id proc_thermal_pci_ids[] = { - { PCI_DEVICE_DATA(INTEL, ADL_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_MBOX) }, - { PCI_DEVICE_DATA(INTEL, MTLP_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_MBOX | PROC_THERMAL_FEATURE_DLVR) }, - { PCI_DEVICE_DATA(INTEL, RPL_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_MBOX) }, + { PCI_DEVICE_DATA(INTEL, ADL_THERMAL, PROC_THERMAL_FEATURE_RAPL | + PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WLT_REQ) }, + { PCI_DEVICE_DATA(INTEL, MTLP_THERMAL, PROC_THERMAL_FEATURE_RAPL | + PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WLT_REQ | + PROC_THERMAL_FEATURE_DLVR) }, + { PCI_DEVICE_DATA(INTEL, RPL_THERMAL, PROC_THERMAL_FEATURE_RAPL | + PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WLT_REQ) }, { }, }; diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c index 09e032f822f3..b8c58a44fb93 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c @@ -137,7 +137,8 @@ static const struct pci_device_id proc_thermal_pci_ids[] = { { PCI_DEVICE_DATA(INTEL, ICL_THERMAL, PROC_THERMAL_FEATURE_RAPL) }, { PCI_DEVICE_DATA(INTEL, JSL_THERMAL, 0) }, { PCI_DEVICE_DATA(INTEL, SKL_THERMAL, PROC_THERMAL_FEATURE_RAPL) }, - { PCI_DEVICE_DATA(INTEL, TGL_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_MBOX) }, + { PCI_DEVICE_DATA(INTEL, TGL_THERMAL, PROC_THERMAL_FEATURE_RAPL | + PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_WLT_REQ) }, { }, }; diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c index 0b89a4340ff4..ec766c5615b7 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c @@ -10,18 +10,12 @@ #include #include "processor_thermal_device.h" -#define MBOX_CMD_WORKLOAD_TYPE_READ 0x0E -#define MBOX_CMD_WORKLOAD_TYPE_WRITE 0x0F - #define MBOX_OFFSET_DATA 0x5810 #define MBOX_OFFSET_INTERFACE 0x5818 #define MBOX_BUSY_BIT 31 #define MBOX_RETRY_COUNT 100 -#define MBOX_DATA_BIT_VALID 31 -#define MBOX_DATA_BIT_AC_DC 30 - static DEFINE_MUTEX(mbox_lock); static int wait_for_mbox_ready(struct proc_thermal_device *proc_priv) @@ -114,128 +108,4 @@ int processor_thermal_send_mbox_write_cmd(struct pci_dev *pdev, u16 id, u32 data } EXPORT_SYMBOL_NS_GPL(processor_thermal_send_mbox_write_cmd, INT340X_THERMAL); -/* List of workload types */ -static const char * const workload_types[] = { - "none", - "idle", - "semi_active", - "bursty", - "sustained", - "battery_life", - NULL -}; - -static ssize_t workload_available_types_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int i = 0; - int ret = 0; - - while (workload_types[i] != NULL) - ret += sprintf(&buf[ret], "%s ", workload_types[i++]); - - ret += sprintf(&buf[ret], "\n"); - - return ret; -} - -static DEVICE_ATTR_RO(workload_available_types); - -static ssize_t workload_type_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct pci_dev *pdev = to_pci_dev(dev); - char str_preference[15]; - u32 data = 0; - ssize_t ret; - - ret = sscanf(buf, "%14s", str_preference); - if (ret != 1) - return -EINVAL; - - ret = match_string(workload_types, -1, str_preference); - if (ret < 0) - return ret; - - ret &= 0xff; - - if (ret) - data = BIT(MBOX_DATA_BIT_VALID) | BIT(MBOX_DATA_BIT_AC_DC); - - data |= ret; - - ret = send_mbox_write_cmd(pdev, MBOX_CMD_WORKLOAD_TYPE_WRITE, data); - if (ret) - return false; - - return count; -} - -static ssize_t workload_type_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct pci_dev *pdev = to_pci_dev(dev); - u64 cmd_resp; - int ret; - - ret = send_mbox_read_cmd(pdev, MBOX_CMD_WORKLOAD_TYPE_READ, &cmd_resp); - if (ret) - return false; - - cmd_resp &= 0xff; - - if (cmd_resp > ARRAY_SIZE(workload_types) - 1) - return -EINVAL; - - return sprintf(buf, "%s\n", workload_types[cmd_resp]); -} - -static DEVICE_ATTR_RW(workload_type); - -static struct attribute *workload_req_attrs[] = { - &dev_attr_workload_available_types.attr, - &dev_attr_workload_type.attr, - NULL -}; - -static const struct attribute_group workload_req_attribute_group = { - .attrs = workload_req_attrs, - .name = "workload_request" -}; - -static bool workload_req_created; - -int proc_thermal_mbox_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv) -{ - u64 cmd_resp; - int ret; - - /* Check if there is a mailbox support, if fails return success */ - ret = send_mbox_read_cmd(pdev, MBOX_CMD_WORKLOAD_TYPE_READ, &cmd_resp); - if (ret) - return 0; - - ret = sysfs_create_group(&pdev->dev.kobj, &workload_req_attribute_group); - if (ret) - return ret; - - workload_req_created = true; - - return 0; -} -EXPORT_SYMBOL_GPL(proc_thermal_mbox_add); - -void proc_thermal_mbox_remove(struct pci_dev *pdev) -{ - if (workload_req_created) - sysfs_remove_group(&pdev->dev.kobj, &workload_req_attribute_group); - - workload_req_created = false; - -} -EXPORT_SYMBOL_GPL(proc_thermal_mbox_remove); - MODULE_LICENSE("GPL v2"); diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_wlt_req.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_wlt_req.c new file mode 100644 index 000000000000..d22c86fad231 --- /dev/null +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_wlt_req.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * processor thermal device for Workload type hints + * update from user space + * + * Copyright (c) 2020-2023, Intel Corporation. + */ + +#include +#include "processor_thermal_device.h" + +/* List of workload types */ +static const char * const workload_types[] = { + "none", + "idle", + "semi_active", + "bursty", + "sustained", + "battery_life", + NULL +}; + +static ssize_t workload_available_types_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int i = 0; + int ret = 0; + + while (workload_types[i] != NULL) + ret += sprintf(&buf[ret], "%s ", workload_types[i++]); + + ret += sprintf(&buf[ret], "\n"); + + return ret; +} + +static DEVICE_ATTR_RO(workload_available_types); + +static ssize_t workload_type_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + char str_preference[15]; + u32 data = 0; + ssize_t ret; + + ret = sscanf(buf, "%14s", str_preference); + if (ret != 1) + return -EINVAL; + + ret = match_string(workload_types, -1, str_preference); + if (ret < 0) + return ret; + + ret &= 0xff; + + if (ret) + data = BIT(MBOX_DATA_BIT_VALID) | BIT(MBOX_DATA_BIT_AC_DC); + + data |= ret; + + ret = processor_thermal_send_mbox_write_cmd(pdev, MBOX_CMD_WORKLOAD_TYPE_WRITE, data); + if (ret) + return false; + + return count; +} + +static ssize_t workload_type_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct pci_dev *pdev = to_pci_dev(dev); + u64 cmd_resp; + int ret; + + ret = processor_thermal_send_mbox_read_cmd(pdev, MBOX_CMD_WORKLOAD_TYPE_READ, &cmd_resp); + if (ret) + return false; + + cmd_resp &= 0xff; + + if (cmd_resp > ARRAY_SIZE(workload_types) - 1) + return -EINVAL; + + return sprintf(buf, "%s\n", workload_types[cmd_resp]); +} + +static DEVICE_ATTR_RW(workload_type); + +static struct attribute *workload_req_attrs[] = { + &dev_attr_workload_available_types.attr, + &dev_attr_workload_type.attr, + NULL +}; + +static const struct attribute_group workload_req_attribute_group = { + .attrs = workload_req_attrs, + .name = "workload_request" +}; + +static bool workload_req_created; + +int proc_thermal_wlt_req_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv) +{ + u64 cmd_resp; + int ret; + + /* Check if there is a mailbox support, if fails return success */ + ret = processor_thermal_send_mbox_read_cmd(pdev, MBOX_CMD_WORKLOAD_TYPE_READ, &cmd_resp); + if (ret) + return 0; + + ret = sysfs_create_group(&pdev->dev.kobj, &workload_req_attribute_group); + if (ret) + return ret; + + workload_req_created = true; + + return 0; +} +EXPORT_SYMBOL_GPL(proc_thermal_wlt_req_add); + +void proc_thermal_wlt_req_remove(struct pci_dev *pdev) +{ + if (workload_req_created) + sysfs_remove_group(&pdev->dev.kobj, &workload_req_attribute_group); + + workload_req_created = false; + +} +EXPORT_SYMBOL_GPL(proc_thermal_wlt_req_remove); + +MODULE_IMPORT_NS(INT340X_THERMAL); +MODULE_LICENSE("GPL"); From patchwork Tue Jun 20 23:01:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 110714 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4008975vqr; Tue, 20 Jun 2023 16:42:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4K5szoxLRQbKvZhwOHwOJc0iWGzw1o4i2YOS1SlUhVZ30ihyFo+fBNkfIUzUodPrash3KQ X-Received: by 2002:a54:4694:0:b0:39b:8121:4e32 with SMTP id k20-20020a544694000000b0039b81214e32mr11526476oic.4.1687304540267; Tue, 20 Jun 2023 16:42:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687304540; cv=none; d=google.com; s=arc-20160816; b=QEWVFnkFYKS+pJMLFQHBJLsGpf3hiNQyNk0PYbso/b7617Ulonzh4x8t42Ytx1UyhX VovvdvZXiUEbichOooEDkpY8ZYFBcr2hNuyq/erJnH652L+dcDrqh5uRCxgt4tKot4/n p7HfOQz0FFr8z+U8kOiSHGDpSsreqZ06N/7xsDzD6kxwRbI91hMedczkaGJKnuglyzNm 1+MiOErYpsh+yKIORhkkTIpQq5UNRiqbcqYOPRc/P7EpRQXc5kJ/GY8PvrWaVlXhAmSy ylCsfRT1BvVwSanCxm8FkiuvXdJBL880cFxC8xQMC0fN0rWdSBVKM2yTf1CDFhXqOQw8 EIFA== 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; bh=/l3+buwl8P9PdeWuhr5p9G3veiOFeZ1E7Sp47gv+sQk=; b=cyg+K6ewumTt5xh4PbFbMTBLWTE2UKSWo3CqFUghNeQj09R8uvV08o/W6Ej2SyYIBT EdSOijv8ReVXD/ht4oFmHCLpKNzdh910uzhRfn73pBYV08q3g7AGMsrRREHp29uBbNOU ZpcJPvx140RBH7gcwgEBit+DBMPjs0GozT7ABNDJyIXn3SUFMOWVynosq6SbmihO7cdF xz41ivyzJJ91J4Lb/gGXL+Vn0xe7pMSc6FuLhOg2EGC5P7SpxaIYRsK0d+nQSlJ+GXbz xEttwoobvtaGUTDNnTzkj9MZaRvG/K2UTvTmVwyhP67KolK6vokcJBy8HNCnQWqftDxX zeIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S3w55MnY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f29-20020a63381d000000b005533db5fbb0si989090pga.379.2023.06.20.16.42.06; Tue, 20 Jun 2023 16:42:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S3w55MnY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230030AbjFTXB6 (ORCPT + 99 others); Tue, 20 Jun 2023 19:01:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229931AbjFTXBz (ORCPT ); Tue, 20 Jun 2023 19:01:55 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 476A2CD; Tue, 20 Jun 2023 16:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687302114; x=1718838114; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0S2CzFuoa7jBPBYtjg///3v2rQKx+t10A4Zc3tSMGYc=; b=S3w55MnYTM29zs9q2Byq9GuQ8+20uM3ePuppvoKdUtS0dcqS2zWUSOdJ usQSKysVnRKkvlgc78i40vCIEHHRRJIY8sX3bXHXaDkhf1u5No99GniIo qMhqVakWLgKzwo0zUsQnG0Hm0ofxaNmUL4Mk3bqVUWkHapaqVKxwQd1ss +v3/xxRwaEDqFOQ/TletyLxOOVxP05KpOk+saV4v9SCZhLV4F0rUwj636 7lajoHu4kXczV4kj9Wn+wlI2Ncav+l3EYfTJy15lheLF7GN/b3nGk9wTe XaiwmAyrHczp8LKyyoPJ4mdtYZ60V6A+H3HnEeFvgpAb6XukFMMxQ3aqn g==; X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="340347277" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="340347277" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 16:01:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="1044465318" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="1044465318" Received: from spandruv-desk.jf.intel.com ([10.54.75.8]) by fmsmga005.fm.intel.com with ESMTP; 20 Jun 2023 16:01:53 -0700 From: Srinivas Pandruvada To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH 2/7] thermal: int340x: processor_thermal: Add interrupt configuration Date: Tue, 20 Jun 2023 16:01:45 -0700 Message-Id: <20230620230150.3068704-3-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> References: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769267045746657093?= X-GMAIL-MSGID: =?utf-8?q?1769267045746657093?= Some features on this PCI devices require interrupt support. Here interrupts are enabled/disabled via sending mailbox commands. The mailbox command ID is 0x1E for read and 0x1F for write. The interrupt configuration will require mutex protection as it involved read-modify-write operation. Since mutex are already used in the mailbox read/write functions: send_mbox_write_cmd() and send_mbox_read_cmd(), there will be double locking. But, this can be avoided by moving mutexes from mailbox read/write processing functions to the calling (exported) functions. Signed-off-by: Srinivas Pandruvada --- .../processor_thermal_device.h | 2 + .../int340x_thermal/processor_thermal_mbox.c | 85 ++++++++++++++----- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h index 7cdeca2edc21..defc919cb020 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h @@ -91,6 +91,8 @@ void proc_thermal_wlt_req_remove(struct pci_dev *pdev); int processor_thermal_send_mbox_read_cmd(struct pci_dev *pdev, u16 id, u64 *resp); int processor_thermal_send_mbox_write_cmd(struct pci_dev *pdev, u16 id, u32 data); +int processor_thermal_mbox_interrupt_config(struct pci_dev *pdev, bool enable, int enable_bit, + int time_window); int proc_thermal_add(struct device *dev, struct proc_thermal_device *priv); void proc_thermal_remove(struct proc_thermal_device *proc_priv); int proc_thermal_suspend(struct device *dev); diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c index ec766c5615b7..7ef0af3f5bef 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c @@ -45,23 +45,16 @@ static int send_mbox_write_cmd(struct pci_dev *pdev, u16 id, u32 data) int ret; proc_priv = pci_get_drvdata(pdev); - - mutex_lock(&mbox_lock); - ret = wait_for_mbox_ready(proc_priv); if (ret) - goto unlock_mbox; + return ret; writel(data, (proc_priv->mmio_base + MBOX_OFFSET_DATA)); /* Write command register */ reg_data = BIT_ULL(MBOX_BUSY_BIT) | id; writel(reg_data, (proc_priv->mmio_base + MBOX_OFFSET_INTERFACE)); - ret = wait_for_mbox_ready(proc_priv); - -unlock_mbox: - mutex_unlock(&mbox_lock); - return ret; + return wait_for_mbox_ready(proc_priv); } static int send_mbox_read_cmd(struct pci_dev *pdev, u16 id, u64 *resp) @@ -71,12 +64,9 @@ static int send_mbox_read_cmd(struct pci_dev *pdev, u16 id, u64 *resp) int ret; proc_priv = pci_get_drvdata(pdev); - - mutex_lock(&mbox_lock); - ret = wait_for_mbox_ready(proc_priv); if (ret) - goto unlock_mbox; + return ret; /* Write command register */ reg_data = BIT_ULL(MBOX_BUSY_BIT) | id; @@ -84,28 +74,85 @@ static int send_mbox_read_cmd(struct pci_dev *pdev, u16 id, u64 *resp) ret = wait_for_mbox_ready(proc_priv); if (ret) - goto unlock_mbox; + return ret; if (id == MBOX_CMD_WORKLOAD_TYPE_READ) *resp = readl(proc_priv->mmio_base + MBOX_OFFSET_DATA); else *resp = readq(proc_priv->mmio_base + MBOX_OFFSET_DATA); -unlock_mbox: - mutex_unlock(&mbox_lock); - return ret; + return 0; } int processor_thermal_send_mbox_read_cmd(struct pci_dev *pdev, u16 id, u64 *resp) { - return send_mbox_read_cmd(pdev, id, resp); + int ret; + + mutex_lock(&mbox_lock); + ret = send_mbox_read_cmd(pdev, id, resp); + mutex_unlock(&mbox_lock); + + return ret; } EXPORT_SYMBOL_NS_GPL(processor_thermal_send_mbox_read_cmd, INT340X_THERMAL); int processor_thermal_send_mbox_write_cmd(struct pci_dev *pdev, u16 id, u32 data) { - return send_mbox_write_cmd(pdev, id, data); + int ret; + + mutex_lock(&mbox_lock); + ret = send_mbox_write_cmd(pdev, id, data); + mutex_unlock(&mbox_lock); + + return ret; } EXPORT_SYMBOL_NS_GPL(processor_thermal_send_mbox_write_cmd, INT340X_THERMAL); +#define MBOX_CAMARILLO_RD_INTR_CONFIG 0x1E +#define MBOX_CAMARILLO_WR_INTR_CONFIG 0x1F +#define WLT_TW_MASK GENMASK_ULL(30, 24) +#define SOC_PREDICTION_TW_SHIFT 24 + +int processor_thermal_mbox_interrupt_config(struct pci_dev *pdev, bool enable, + int enable_bit, int time_window) +{ + u64 data; + int ret; + + if (!pdev) + return -ENODEV; + + mutex_lock(&mbox_lock); + + /* Do read modify write for MBOX_CAMARILLO_RD_INTR_CONFIG */ + + ret = send_mbox_read_cmd(pdev, MBOX_CAMARILLO_RD_INTR_CONFIG, &data); + if (ret) { + dev_err(&pdev->dev, "MBOX_CAMARILLO_RD_INTR_CONFIG failed\n"); + goto unlock; + } + + if (time_window >= 0) { + data &= ~WLT_TW_MASK; + + /* Program notification delay */ + data |= (time_window << SOC_PREDICTION_TW_SHIFT); + } + + if (enable) + data |= BIT(enable_bit); + else + data &= ~BIT(enable_bit); + + ret = send_mbox_write_cmd(pdev, MBOX_CAMARILLO_WR_INTR_CONFIG, data); + if (ret) + dev_err(&pdev->dev, "MBOX_CAMARILLO_WR_INTR_CONFIG failed\n"); + +unlock: + mutex_unlock(&mbox_lock); + + return ret; +} +EXPORT_SYMBOL_NS_GPL(processor_thermal_mbox_interrupt_config, INT340X_THERMAL); + MODULE_LICENSE("GPL v2"); From patchwork Tue Jun 20 23:01:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 110710 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4000463vqr; Tue, 20 Jun 2023 16:21:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4cfXZ82EbqhYtb1mEephERWcfASxiOv2/isiRKzyjF+AUfftIdiP4bMT/tAVrw9NKYWyZu X-Received: by 2002:a9d:5e10:0:b0:6b4:541d:555c with SMTP id d16-20020a9d5e10000000b006b4541d555cmr8114708oti.31.1687303294324; Tue, 20 Jun 2023 16:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687303294; cv=none; d=google.com; s=arc-20160816; b=z3DoHwhPZ3rfVXTdgYaSjplvymvKye1XzFqyRh5IZCRb4OdDZx1GZxbsS+JduxVNHE K9+xKqRik98INpdoImcCo7B7ICFtSr74bIsllT+HNwi4MO/h1ogM/lJd1jGHhRcoCtLH 3ruWxXbY8vgA3rFVvhdX9Ft4mrmiBd3FYXdBhuvV5JBKaBZNCi5FpgUlEj6nurK6xP++ dtGGNdiYGAFOhVN6hf5LsXJcnnmqFyvPhukNxknZ4YSPsTm+wjK16vJD8tQEWPe2hhyd IIWIgr1uM6t49QuguAuARJ/Z2+T2WxvlVHw6nNdiVNOlEkPgReKK/Vz9gZ1mH+2p39x1 +Ngw== 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; bh=NIzD/e21LQVNNkiWHBBFoSnRp1gTSvamo1UM9x3gxEY=; b=f4Amwm1DWtPVmex0xIxu2dzJ3NcID1Ijvr8dOuc52o3M72yc5ylbOYme5cQW8VNghG moqRsGHqlZc/VsP+xa7i2K+IUejGV1ork1NsVkYnCRel+k2xwXXEGSeyha9KTG4JTO2H HY+MoFIKVsxtFVaDhz/e7IY8wmjdlAxMSQkTBlmbkM/I4Sso8Fg0JpmQa1QZzdEJNp46 vjQoAbi2sl2jIJWIuKesoTdAKVu02a8b59reSrajfC26WBLPUpsuujYypi4ZSvgxREZ+ jtG6zkU1XuQLsIyZT41VqtAUw0X/N9U1OfPimdKkvXmcMTB940fcdx2P98YjwInU08B1 v/mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fVVErAIb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v3-20020a655c43000000b005539899e4cdsi2529869pgr.813.2023.06.20.16.21.20; Tue, 20 Jun 2023 16:21:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fVVErAIb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230117AbjFTXCO (ORCPT + 99 others); Tue, 20 Jun 2023 19:02:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbjFTXB4 (ORCPT ); Tue, 20 Jun 2023 19:01:56 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99E6019B; Tue, 20 Jun 2023 16:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687302115; x=1718838115; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CEYJChC6OvSO8x/YfH7LNbtmj//EuKold9s1r0acTp8=; b=fVVErAIbLReqPQ/oFsaLqwL1e5WAIv5rVSLyuZCADy2T4ZiPw4e+XIxk wGvAfpJ+O3IhBYIgIKuZhPT9szxjq96QRV+i0gGMcyRZ5d0HagGFyg5XN CvNmTvR0SFH1Lcz82LT0is5jlqsXnlKwExutbF74scopB9/u4V4pp0QpZ ZfFQhEH7Y9NHVyb0aGVusalNG5UqtXQMtebF3PWAaDLERwsh9g1rwLcfC Y/Tw7EyQwz6WQ16E3Au0ejKHsRvPW/eFoNabwN4Nf8q6EoFnjmii3njbA hqAMl1sJPpqBzvBSyGH6imCmJySn72BApjniRP+pe8Tel8XVZsqLkpCIa A==; X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="340347281" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="340347281" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 16:01:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="1044465323" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="1044465323" Received: from spandruv-desk.jf.intel.com ([10.54.75.8]) by fmsmga005.fm.intel.com with ESMTP; 20 Jun 2023 16:01:53 -0700 From: Srinivas Pandruvada To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH 3/7] thermal: int340x: processor_thermal: Use non MSI interrupts Date: Tue, 20 Jun 2023 16:01:46 -0700 Message-Id: <20230620230150.3068704-4-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> References: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769265738966856552?= X-GMAIL-MSGID: =?utf-8?q?1769265738966856552?= There are issues in using MSI interrupts for processor thermal device. The support is not consistent, across generations. Even in the same generation, there are issue in getting interrupts via MSI. Hence always use legacy PCI interrupts by default, instead of MSI. Add a module param to use of MSI, so that MSI can be still used. Signed-off-by: Srinivas Pandruvada --- .../processor_thermal_device_pci.c | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c index 5a2bcfff0a68..057778f7bece 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c @@ -15,6 +15,11 @@ #define DRV_NAME "proc_thermal_pci" +static int msi_enabled; +module_param(msi_enabled, int, 0644); +MODULE_PARM_DESC(msi_enabled, + "Use PCI MSI based interrupts for processor thermal device."); + struct proc_thermal_pci { struct pci_dev *pdev; struct proc_thermal_device *proc_priv; @@ -219,8 +224,6 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_ return ret; } - pci_set_master(pdev); - INIT_DELAYED_WORK(&pci_info->work, proc_thermal_threshold_work_fn); ret = proc_thermal_add(&pdev->dev, proc_priv); @@ -248,16 +251,23 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_ goto err_ret_mmio; } - /* request and enable interrupt */ - ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to allocate vectors!\n"); - goto err_ret_tzone; - } - if (!pdev->msi_enabled && !pdev->msix_enabled) + if (msi_enabled) { + pci_set_master(pdev); + /* request and enable interrupt */ + ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES); + if (ret < 0) { + dev_err(&pdev->dev, "Failed to allocate vectors!\n"); + goto err_ret_tzone; + } + if (!pdev->msi_enabled && !pdev->msix_enabled) + irq_flag = IRQF_SHARED; + + irq = pci_irq_vector(pdev, 0); + } else { irq_flag = IRQF_SHARED; + irq = pdev->irq; + } - irq = pci_irq_vector(pdev, 0); ret = devm_request_threaded_irq(&pdev->dev, irq, proc_thermal_irq_handler, NULL, irq_flag, KBUILD_MODNAME, pci_info); @@ -273,7 +283,8 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_ return 0; err_free_vectors: - pci_free_irq_vectors(pdev); + if (msi_enabled) + pci_free_irq_vectors(pdev); err_ret_tzone: thermal_zone_device_unregister(pci_info->tzone); err_ret_mmio: From patchwork Tue Jun 20 23:01:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 110715 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4020384vqr; Tue, 20 Jun 2023 17:08:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6qTx8qLLG3hhMx6QktYGlSfK1ck5aJ8Tr62Zg35eU2kDjgryhlix1sPIwPG/fNCLPRNDTB X-Received: by 2002:a17:90b:298:b0:25b:ce40:7dd6 with SMTP id az24-20020a17090b029800b0025bce407dd6mr10261690pjb.33.1687306094416; Tue, 20 Jun 2023 17:08:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687306094; cv=none; d=google.com; s=arc-20160816; b=VUMN1To6Pkokn0Dm1hrHC7aAWmvC6x+glOIeiuA13N08bmPo7Gku4KqzEodLAUyw0L A8u+mLGMkhemWb1ZBxESEvVo+2sRSFPVPNWp4ZBrwnOLTDekPMh9YAtOb2Z69udioc1u ogsCSwt+sY1Bge1HbuAsVKwc9p6zsuxTIrzrpDwtQHX7+b6oSZU6a9ADbg6yP5t/o1q2 AKfcIgNsPfbArU6BhaP8RkO/cBdFLIiTU5/8z4RAlWrGNmuQo7+ltJlvQnYJyo0x/0gE ljOs7Lp5VqCMmZkZQNerm3TSycRAaM4hoWNCor0XS/eQefyQCWWY66+WNOKV4cqTcubq nxlg== 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; bh=yHqABD98xyzZs3KKuko/36RTKACScq9x55FTrylto04=; b=aED5Z2zw4+lzL+UYAjjG8yaA03WYDkt+jCAzRmDpusu/A8wqAxALvWZyGLmgQ7zHzC pbuFlvZzEc6FNATeHNUGoy7BmA6RM85Ikv6uofSmiHp1uOad/rK88m8lSf0tWLWNSmkI EEp+eIql2ugLcAekJEN0wK93yt5Nz0SvmbIKAbdcvapCh/LdUbg4gByRAbc3oHtiXQ6h Pt8IR0DVIPD7grkGEvURjifqmPjR0Vjj9CmK7ASI8pHGzYjzxmSKOiqu7yz/D0uAJW93 q+LZ7WdVphxPxYApKezJDMMDfRy+uj6m72sxF8sQz/9xdxnFJjTyfoqFcKL6OGW9eLVd RlLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k2XToIDE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u16-20020a170902e81000b001a94b91f402si3333003plg.218.2023.06.20.17.08.01; Tue, 20 Jun 2023 17:08:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k2XToIDE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230073AbjFTXCR (ORCPT + 99 others); Tue, 20 Jun 2023 19:02:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229989AbjFTXB5 (ORCPT ); Tue, 20 Jun 2023 19:01:57 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C7FB10DA; Tue, 20 Jun 2023 16:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687302115; x=1718838115; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aHAH3gbVtLE8GRguVc1WMS2QGhQBERba7NOQ9xfAKEE=; b=k2XToIDEQsCbcvWIVMVqeQNkeQb2BiVmB0TtY7kklFcZePbolA7ST3dK onN47k8dmWQaO7DExDbFcoENqKcxGX8pdoxRd5gyO8cmaYmgL8hDxmbzQ Gz+gyaL8ynGiBeryv9eh7N0A5Rk78BZifJc5H+vKiiaj0EingyV/4anIm eTHbvGFtNCNLyynEPAJbFYdn26gvTOL3P+cDxxzQPCn9iCH3s1VxKesDU B1Y/Z2pi3vuaiFwSqGg8K79NqHT9HkiiD9joV349sHYg0HDb05oWQoqMR SQXgnIHvo5Ngihf4zKs5Vha9nxEerQmb11oJvjO2dKPnJG780fGfbYE3c A==; X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="340347288" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="340347288" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 16:01:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="1044465328" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="1044465328" Received: from spandruv-desk.jf.intel.com ([10.54.75.8]) by fmsmga005.fm.intel.com with ESMTP; 20 Jun 2023 16:01:54 -0700 From: Srinivas Pandruvada To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH 4/7] thermal/drivers/int340x: Remove PROC_THERMAL_FEATURE_WLT_REQ for Meteor Lake Date: Tue, 20 Jun 2023 16:01:47 -0700 Message-Id: <20230620230150.3068704-5-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> References: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769268675256312142?= X-GMAIL-MSGID: =?utf-8?q?1769268675256312142?= Meteor Lake processor supports firmware hints for predicting workload type. So, remove support for passing workload hints to the firmware. Signed-off-by: Srinivas Pandruvada Reviewed-by: Zhang Rui --- .../intel/int340x_thermal/processor_thermal_device_pci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c index 057778f7bece..3dab3dbdbbc6 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c @@ -364,8 +364,7 @@ static const struct pci_device_id proc_thermal_pci_ids[] = { { PCI_DEVICE_DATA(INTEL, ADL_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WLT_REQ) }, { PCI_DEVICE_DATA(INTEL, MTLP_THERMAL, PROC_THERMAL_FEATURE_RAPL | - PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WLT_REQ | - PROC_THERMAL_FEATURE_DLVR) }, + PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_DLVR) }, { PCI_DEVICE_DATA(INTEL, RPL_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WLT_REQ) }, { }, From patchwork Tue Jun 20 23:01:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 110713 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4008115vqr; Tue, 20 Jun 2023 16:40:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4nc1wdhPth9235dDIDHcWRGhQuTal/WbRNvs39P4suJhdxDqAAr0AHLNuIpnULBGdLvAex X-Received: by 2002:a05:6a00:8cc:b0:666:ae6b:c484 with SMTP id s12-20020a056a0008cc00b00666ae6bc484mr17678011pfu.13.1687304407853; Tue, 20 Jun 2023 16:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687304407; cv=none; d=google.com; s=arc-20160816; b=rTqSAbM7jMZPM88isgApeUJHcXl2wefx8CUSe9xUKjzPocSlC+witep/tM0PJxx68t sbISBVctWOQGrFLrL+MXuWnwF+cQoLESeHUlSzSeRph8HNJe2VNTTD5rXA2qKbd9/Xxb Dou8+Tu/xSH8OJ++Y1k12jYeBoH3nXQcWO7PUzU/LmNDWLi+Fvo9QgXW6kPfL7Bk0895 89mp4mDT7tQiv1XsEey+KRU35VtWn95Hl88I4KE7SGT7djAX9/GsUJzuTWCbrXcsonUq voTkwJx8Y2S3oTcIiHjz9OoaUyaFndi7uWD6xu5QRPjmnOFmVI2dcGvj5qhJNAsgGbhC Uiug== 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; bh=pS1SVPGx18VsB9KjmqSUzzvRyTfzoHzmW/rsivqBwwA=; b=kuH6s8fxkfgvmhHfk70jBYj+IZipEYqATJutWEjOWDsq2rzdPFOigFvaz4kv5XfnU0 S4U7/9ftHC+xoXwobzLGNsRD6DhNvi2BOyrajDMNPFx2nVYz03iDocu56ZSuN6DA8unT ie4/Q83vBBQFGV5FJmGeh+5N5Ggv6Yzt1wWoETIGKfeWZUlvblHuosaZOPteIHopU/VH +IdUNly/7Hg8acCLC1bzs4y2C4RnYpNItW/ct5Z/QdJ3iUJdCUabSD6HL+nlPVurs4PG 62OCF6eQajPqQwgvwrlb08TL1DgdPKezPBD/lT/i9BRNBCl2pgXESAASyMtXs9WcShku /ItQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="k5kxrj/y"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x3-20020aa79563000000b006688abf7436si2701880pfq.116.2023.06.20.16.39.53; Tue, 20 Jun 2023 16:40:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="k5kxrj/y"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230170AbjFTXCV (ORCPT + 99 others); Tue, 20 Jun 2023 19:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbjFTXB5 (ORCPT ); Tue, 20 Jun 2023 19:01:57 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EFDB10F4; Tue, 20 Jun 2023 16:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687302115; x=1718838115; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=33VAMB7NK7lelfQM36j1lNsCyczwY2c4/0rCGB/Y1Is=; b=k5kxrj/yhVRF24/7XULEcJ1XEces0Cb6qHD+DI2h9FE5CAvuLsjEcjBK wTvgWkDzCgHkW0+yDxNv9uZWpq5pLnSPMMPsCWzGNSwiQpNGNOTtKv4DL 6hei/KWQ6bUjJBj01ntySOEfw/7HUiNu1RhkbTmz/SJAHnzWmP0f2CorK lVBD7rJJn44WPt5tRKPJpr3mVX4hQ+jyzLaSnvMgdrZR9bA546gTm5mO1 nShW+U2lfUZzcAb/yMQY0zZ2CeSihIgnByyKMJakwUIpoZlprHk3PkNQq Avbj1a1wX0HucG4E1oZv/+HdwEvNvglczAWY7EcT8ZySUgJoQlhFYh5lQ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="340347296" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="340347296" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 16:01:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="1044465332" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="1044465332" Received: from spandruv-desk.jf.intel.com ([10.54.75.8]) by fmsmga005.fm.intel.com with ESMTP; 20 Jun 2023 16:01:54 -0700 From: Srinivas Pandruvada To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH 5/7] thermal: int340x: processor_thermal: Add workload type hint Date: Tue, 20 Jun 2023 16:01:48 -0700 Message-Id: <20230620230150.3068704-6-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> References: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769266906840815985?= X-GMAIL-MSGID: =?utf-8?q?1769266906840815985?= Prior to Meteor Lake processor generation, user space can pass workload type request to the firmware. Then firmware can optimize power based on workload type. User space also uses workload type request to implement its own heuristics. The firmware in Meteor Lake processor generation is capable of predicting workload type without user space. To avoid duplicate processing, the user space can read the same workload type hint from the firmware instead of implementing its own prediction. This workload hint is passed from the firmware via a MMIO offset 0x5B18. Before receiving the hint, firmware needs to be configured via a mailbox command. This mailbox command enables interrupt and notification delay. This notification delay can be changed from user space. This workload hint is passed via sysfs attribute group "workload_hint". This attribute group contains following attributes: workload_type_enable: Enables/disables workload type hints from the firmware. notification_delay_ms: Notification delay in milli seconds. workload_type_index: The current workload type index predicted by the firmware. Refer to the documentation for meaning of each index value. Signed-off-by: Srinivas Pandruvada --- .../driver-api/thermal/intel_dptf.rst | 38 +++ .../thermal/intel/int340x_thermal/Makefile | 1 + .../processor_thermal_device.c | 9 + .../processor_thermal_device.h | 7 + .../processor_thermal_device_pci.c | 3 +- .../processor_thermal_wlt_hint.c | 239 ++++++++++++++++++ 6 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 drivers/thermal/intel/int340x_thermal/processor_thermal_wlt_hint.c diff --git a/Documentation/driver-api/thermal/intel_dptf.rst b/Documentation/driver-api/thermal/intel_dptf.rst index 9ab4316322a1..5cba02c4c308 100644 --- a/Documentation/driver-api/thermal/intel_dptf.rst +++ b/Documentation/driver-api/thermal/intel_dptf.rst @@ -315,3 +315,41 @@ DPTF Fan Control ---------------------------------------- Refer to Documentation/admin-guide/acpi/fan_performance_states.rst + +Workload Type Hints +---------------------------------------- + +The firmware in Meteor Lake processor generation is capable of predicting +workload type and pass hints to OS. These hints can be enabled and read +from user space. User space can poll attribute "workload_type_index" for +the current hint or can get notification when this attribute is changed. + +file:`/sys/bus/pci/devices/0000:00:04.0/workload_hint/` + +``workload_hint_enable`` (RW) + Enable firmware to send workload type hints from user space. + +``notification_delay_ms`` (RW) + Minimum delay in milli seconds before firmware will notify OS. + +``workload_type_index`` (RO) + Predicted workload type index. + The index and description on Meteor Lake processor: + + 0 - Idle: System performs no tasks, power and residency are consistently + low for long periods of time. + + 1 – Battery Life: Power is relatively low, but the processor may still be + actively performing a task, such as video playback for a long period of + time. + + 2 – Sustained: Power level that is relatively high for a long period + of time, with very few to no periods of idleness, which will eventually + exhaust RAPL Power Limit 1 and 2. + + 3 – Bursty: Consumes a relatively constant average amount of power, + however, bursts of activity interrupt periods of relative idleness. + The bursts are relatively short and spaced with relative idleness + which typically do not exhaust RAPL Power Limit 1. + + 4 – Unknown: Can't classify. diff --git a/drivers/thermal/intel/int340x_thermal/Makefile b/drivers/thermal/intel/int340x_thermal/Makefile index 76e053e541f0..ccd0fdd23161 100644 --- a/drivers/thermal/intel/int340x_thermal/Makefile +++ b/drivers/thermal/intel/int340x_thermal/Makefile @@ -11,5 +11,6 @@ obj-$(CONFIG_PROC_THERMAL_MMIO_RAPL) += processor_thermal_rapl.o obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_rfim.o obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_mbox.o obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_wlt_req.o +obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_wlt_hint.o obj-$(CONFIG_INT3406_THERMAL) += int3406_thermal.o obj-$(CONFIG_ACPI_THERMAL_REL) += acpi_thermal_rel.o diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c index 48f6c72b05f6..127deefbb633 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c @@ -352,6 +352,12 @@ int proc_thermal_mmio_add(struct pci_dev *pdev, dev_err(&pdev->dev, "failed to add MBOX interface\n"); goto err_rem_rfim; } + } else if (feature_mask & PROC_THERMAL_FEATURE_WLT_HINT) { + ret = proc_thermal_wlt_hint_add(pdev, proc_priv); + if (ret) { + dev_err(&pdev->dev, "failed to add WLT Hint\n"); + goto err_rem_rfim; + } } return 0; @@ -376,10 +382,13 @@ void proc_thermal_mmio_remove(struct pci_dev *pdev, struct proc_thermal_device * if (proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_WLT_REQ) proc_thermal_wlt_req_remove(pdev); + else if (proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_WLT_HINT) + proc_thermal_wlt_hint_remove(pdev); } EXPORT_SYMBOL_GPL(proc_thermal_mmio_remove); MODULE_IMPORT_NS(INTEL_TCC); +MODULE_IMPORT_NS(INT340X_THERMAL); MODULE_AUTHOR("Srinivas Pandruvada "); MODULE_DESCRIPTION("Processor Thermal Reporting Device Driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h index defc919cb020..bc056712f728 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.h @@ -61,6 +61,7 @@ struct rapl_mmio_regs { #define PROC_THERMAL_FEATURE_DVFS 0x04 #define PROC_THERMAL_FEATURE_WLT_REQ 0x08 #define PROC_THERMAL_FEATURE_DLVR 0x10 +#define PROC_THERMAL_FEATURE_WLT_HINT 0x20 #if IS_ENABLED(CONFIG_PROC_THERMAL_MMIO_RAPL) int proc_thermal_rapl_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv); @@ -95,6 +96,12 @@ int processor_thermal_mbox_interrupt_config(struct pci_dev *pdev, bool enable, i int time_window); int proc_thermal_add(struct device *dev, struct proc_thermal_device *priv); void proc_thermal_remove(struct proc_thermal_device *proc_priv); + +int proc_thermal_wlt_hint_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv); +void proc_thermal_wlt_hint_remove(struct pci_dev *pdev); +void proc_thermal_wlt_intr_callback(struct pci_dev *pdev, struct proc_thermal_device *proc_priv); +bool proc_thermal_check_wlt_intr(struct proc_thermal_device *proc_priv); + int proc_thermal_suspend(struct device *dev); int proc_thermal_resume(struct device *dev); int proc_thermal_mmio_add(struct pci_dev *pdev, diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c index 3dab3dbdbbc6..edddebedf42e 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c @@ -364,7 +364,8 @@ static const struct pci_device_id proc_thermal_pci_ids[] = { { PCI_DEVICE_DATA(INTEL, ADL_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WLT_REQ) }, { PCI_DEVICE_DATA(INTEL, MTLP_THERMAL, PROC_THERMAL_FEATURE_RAPL | - PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_DLVR) }, + PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_DLVR | + PROC_THERMAL_FEATURE_WLT_HINT) }, { PCI_DEVICE_DATA(INTEL, RPL_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WLT_REQ) }, { }, diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_wlt_hint.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_wlt_hint.c new file mode 100644 index 000000000000..6b72ba665167 --- /dev/null +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_wlt_hint.c @@ -0,0 +1,239 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * processor thermal device for reading Workload type hints + * from the user space. The hints are provided by the firmware. + * + * Operation: + * When user space enables workload type prediction: + * - Use mailbox to configure: + * Configure notification delay + * Enable processor thermal device interrupt + * - The predicted workload type can be read from MMIO: + * Offset 0x5B18 shows if there was an interrupt + * active for change in workload type and also + * predicted workload type. + * + * Two interface function are provided to call when there is a + * thermal device interrupt: + * - proc_thermal_check_wlt_intr(): Check if the is interrupt for + * change in workload type. + * - proc_thermal_wlt_intr_callback(): Callback for interrupt + * under thread context to process. This involves sending + * notification to user space that there is a change in workload + * type. + * + * Copyright (c) 2020-2023, Intel Corporation. + */ + +#include +#include +#include "processor_thermal_device.h" + +#define SOC_WLT_RES_INT_STATUS_OFF 0x5B18 +#define SOC_WLT_MASK GENMASK_ULL(47, 40) + +#define SOC_WLT_PREDICTION_INT_ENABLE_BIT 23 + +#define SOC_WLT_PREDICTION_INT_ACTIVE BIT(2) + +/* + * Closest possible to 1 Second is 1024 ms with programmed time delay + * of 0x0A. + */ +static u8 notify_delay = 0x0A; +static u16 notify_delay_ms = 1024; + +/* Show current predicted workload type index */ +static ssize_t workload_type_index_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct proc_thermal_device *proc_priv; + struct pci_dev *pdev = to_pci_dev(dev); + u64 status = 0; + int wlt; + + proc_priv = pci_get_drvdata(pdev); + + status = readq(proc_priv->mmio_base + SOC_WLT_RES_INT_STATUS_OFF); + wlt = FIELD_GET(SOC_WLT_MASK, status); + + return sysfs_emit(buf, "%d\n", wlt); +} + +static DEVICE_ATTR_RO(workload_type_index); + +static u8 wlt_enable; + +static ssize_t workload_hint_enable_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%d\n", wlt_enable); +} + +/* + * Enable workload type prediction by writing 1 to enable, 0 to + * disable + */ +static ssize_t workload_hint_enable_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + struct pci_dev *pdev = to_pci_dev(dev); + u8 mode; + + if (kstrtou8(buf, 10, &mode) || mode > 1) + return -EINVAL; + + if (mode) { + int ret; + + ret = processor_thermal_mbox_interrupt_config(pdev, true, + SOC_WLT_PREDICTION_INT_ENABLE_BIT, + notify_delay); + if (ret) + return ret; + } else { + processor_thermal_mbox_interrupt_config(pdev, false, + SOC_WLT_PREDICTION_INT_ENABLE_BIT, 0); + } + + wlt_enable = mode; + + return size; +} + +static DEVICE_ATTR_RW(workload_hint_enable); + +static ssize_t notification_delay_ms_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%u\n", notify_delay_ms); +} + +static ssize_t notification_delay_ms_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + struct pci_dev *pdev = to_pci_dev(dev); + u16 new_tw; + int ret; + + /* + * Time window register value: + * Formula: (1 + x/4) * power(2,y) + * x = 2 msbs, that is [30:29] y = 5 [28:24] + * in INTR_CONFIG register. + * The result will be in milli seconds. + * Here, just keep x = 0, and just change y. + * First round up the user value to power of 2 and + * then take log2, to get "y" value to program. + */ + ret = kstrtou16(buf, 10, &new_tw); + if (ret) + return ret; + + if (new_tw) { + u8 tm; + + new_tw = roundup_pow_of_two(new_tw); + tm = ilog2(new_tw); + if (tm > 31) + return -EINVAL; + + ret = processor_thermal_mbox_interrupt_config(pdev, true, + SOC_WLT_PREDICTION_INT_ENABLE_BIT, + tm); + if (ret) + return ret; + + notify_delay = tm; + notify_delay_ms = new_tw; + } else { + ret = processor_thermal_mbox_interrupt_config(pdev, false, + SOC_WLT_PREDICTION_INT_ENABLE_BIT, + notify_delay); + if (ret) + return ret; + } + + return size; +} + +static DEVICE_ATTR_RW(notification_delay_ms); + +static struct attribute *workload_hint_attrs[] = { + &dev_attr_workload_type_index.attr, + &dev_attr_workload_hint_enable.attr, + &dev_attr_notification_delay_ms.attr, + NULL +}; + +static const struct attribute_group workload_hint_attribute_group = { + .attrs = workload_hint_attrs, + .name = "workload_hint" +}; + +/* + * Callback to check if interrupt for prediction is active. + * Caution: Called from interrupt context. + */ +bool proc_thermal_check_wlt_intr(struct proc_thermal_device *proc_priv) +{ + u64 int_status; + + int_status = readq(proc_priv->mmio_base + SOC_WLT_RES_INT_STATUS_OFF); + if (int_status & SOC_WLT_PREDICTION_INT_ACTIVE) + return true; + + return false; +} +EXPORT_SYMBOL_NS_GPL(proc_thermal_check_wlt_intr, INT340X_THERMAL); + +/* Callback to notify user space */ +void proc_thermal_wlt_intr_callback(struct pci_dev *pdev, struct proc_thermal_device *proc_priv) +{ + u64 status; + + status = readq(proc_priv->mmio_base + SOC_WLT_RES_INT_STATUS_OFF); + if (status & SOC_WLT_PREDICTION_INT_ACTIVE) { + writeq(status & ~SOC_WLT_PREDICTION_INT_ACTIVE, + proc_priv->mmio_base + SOC_WLT_RES_INT_STATUS_OFF); + sysfs_notify(&pdev->dev.kobj, "workload_hint", "workload_type_index"); + } +} +EXPORT_SYMBOL_NS_GPL(proc_thermal_wlt_intr_callback, INT340X_THERMAL); + +static bool workload_hint_created; + +int proc_thermal_wlt_hint_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv) +{ + int ret; + + ret = sysfs_create_group(&pdev->dev.kobj, &workload_hint_attribute_group); + if (ret) + return ret; + + workload_hint_created = true; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(proc_thermal_wlt_hint_add, INT340X_THERMAL); + +void proc_thermal_wlt_hint_remove(struct pci_dev *pdev) +{ + processor_thermal_mbox_interrupt_config(pdev, false, + SOC_WLT_PREDICTION_INT_ENABLE_BIT, + notify_delay); + + if (workload_hint_created) + sysfs_remove_group(&pdev->dev.kobj, &workload_hint_attribute_group); + + workload_hint_created = false; +} +EXPORT_SYMBOL_NS_GPL(proc_thermal_wlt_hint_remove, INT340X_THERMAL); + +MODULE_IMPORT_NS(INT340X_THERMAL); +MODULE_LICENSE("GPL"); From patchwork Tue Jun 20 23:01:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 110709 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3996525vqr; Tue, 20 Jun 2023 16:13:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ66nYiTY3qUNBwUGIDDbgad24padoUvvV1GXZfVFGPbUrJ9re/R70uqQPlI25GMMValV6yv X-Received: by 2002:a05:6a21:338b:b0:121:8d14:4963 with SMTP id yy11-20020a056a21338b00b001218d144963mr9234092pzb.7.1687302790472; Tue, 20 Jun 2023 16:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687302790; cv=none; d=google.com; s=arc-20160816; b=Bl7bgnefVOUhziSiCQGmi8tOiYdaRL6t2MZ6aWSEJ5yUZCQ8Xh/aFZ/SVF+VOZ/k/l bJiRk1nmyXPWN5SKteFB2d7NAvH+opssKj+v12CcWyNMbN0nOiNcGnDN3zUcMPUT9juk eaAxKXib7pFwoMLREWIdvlCTNvC7Ym6bZBmfnEQkGKw9IP/fyQpXgfEORMCxfi0aP8eu IXSIwRifTxf831HjJ9qSHa0SWFozyqjgnKAW3KJhV3FQChGpsT1cCCe9HYctbuNe3Lr6 NoNBOLGOmXAXoV7XPanxV1bijYEB7N7sbauwzwkoyNWGw/e8JXlZ52OAsFkrGSd18iH9 pptA== 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; bh=P2NSdd8htwzsoJ4MIbmdPAw5ukNC8UekChioWdHPQR4=; b=fSt1gpJ8xR5KCGOajetOtDjROa7Ug+0mwWdHenyeFezHSCbz9iSztILqxZX9yCCLJe oAQ3j0RF8F5ixWClISfxhx1t4ZKj2RZnxWb9wJtEI6i451+DcpdBaszVguVU/cShuofr MotUV9K5lTn1MGHzwFxIYkYuk+vuswouQOyRG2M3FjeO6IhCQOldeMwie/e1TtWnUgvq tgGAfk0xMbiXxZ+2izIdrGXlYXZMHc+JQB+MVeZa6HrA/JfeYVR5nglW70sH0QEvWKmq SU95GHB1ucdQMH9iGJ4ZyyZRz4a8Hd8uVaHWjHKr2R+OpzDeNrfPL8kj3Q/TzcMcklqQ csCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FeyaMbY4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020aa793cc000000b0064d533abfd4si2721501pff.189.2023.06.20.16.12.56; Tue, 20 Jun 2023 16:13:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FeyaMbY4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbjFTXCU (ORCPT + 99 others); Tue, 20 Jun 2023 19:02:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbjFTXB5 (ORCPT ); Tue, 20 Jun 2023 19:01:57 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 887BECD; Tue, 20 Jun 2023 16:01:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687302116; x=1718838116; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LKmNt3HszQmb/54iu3mxg6VlucMYA5OmGJY2K1UUMO0=; b=FeyaMbY40thCB9Sy2YuK5r1REbMf5+QJ4z5f95UNMDIpmCUrx2OIyWPd M/pimQkiNCV0ygVTeCfKeAzz4fH8rzSfIDx6HWWx/2AvMCqgOc13FBbZY h+bcUMbXW8N/Z6qmOf0G+bAdLqI/EV4quPjDn5C+NqH/JVpqD4pHlOkTC Nn7Ef/B6jQUfvb2XGia99JJI5ulWnTgzLE1KTJCVii0mc1N/63PtInMJI u1UH4b6TO3ETafFioenYjn4ipmz1ZVf2G5r4vD9DMKhRycrYprcdXIhRt 6SPYrOuEB3LDHeu5KIp9OgGxYYjhawdlTvLJmU7yx77t1SgKX/bcyoe5+ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="340347301" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="340347301" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 16:01:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="1044465338" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="1044465338" Received: from spandruv-desk.jf.intel.com ([10.54.75.8]) by fmsmga005.fm.intel.com with ESMTP; 20 Jun 2023 16:01:54 -0700 From: Srinivas Pandruvada To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH 6/7] thermal/drivers/int340x: Support workload hint interrupts Date: Tue, 20 Jun 2023 16:01:49 -0700 Message-Id: <20230620230150.3068704-7-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> References: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769265210549217497?= X-GMAIL-MSGID: =?utf-8?q?1769265210549217497?= On thermal device interrupt, if the interrupt is generated for passing workload hint, call the callback to pass notification to the user space. First call proc_thermal_check_wlt_intr() to check interrupt, if this callback returns true, wake IRQ thread. Call proc_thermal_wlt_intr_callback() to notify user space. While here remove function pkg_thermal_schedule_work() and move the processing to the caller. The function pkg_thermal_schedule_work() just called schedule_delayed_work(). Signed-off-by: Srinivas Pandruvada --- .../processor_thermal_device_pci.c | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c index edddebedf42e..7fa5c3d459bd 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c @@ -115,27 +115,40 @@ static void proc_thermal_threshold_work_fn(struct work_struct *work) proc_thermal_mmio_write(pci_info, PROC_THERMAL_MMIO_INT_ENABLE_0, 1); } -static void pkg_thermal_schedule_work(struct delayed_work *work) +static irqreturn_t proc_thermal_irq_thread_handler(int irq, void *devid) { - unsigned long ms = msecs_to_jiffies(notify_delay_ms); + struct proc_thermal_pci *pci_info = devid; + + proc_thermal_wlt_intr_callback(pci_info->pdev, pci_info->proc_priv); - schedule_delayed_work(work, ms); + return IRQ_HANDLED; } static irqreturn_t proc_thermal_irq_handler(int irq, void *devid) { struct proc_thermal_pci *pci_info = devid; + struct proc_thermal_device *proc_priv; + int ret = IRQ_HANDLED; u32 status; + proc_priv = pci_info->proc_priv; + + if (proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_WLT_HINT) { + if (proc_thermal_check_wlt_intr(pci_info->proc_priv)) + ret = IRQ_WAKE_THREAD; + } + proc_thermal_mmio_read(pci_info, PROC_THERMAL_MMIO_INT_STATUS_0, &status); + if (status) { + unsigned long ms = msecs_to_jiffies(notify_delay_ms); - /* Disable enable interrupt flag */ - proc_thermal_mmio_write(pci_info, PROC_THERMAL_MMIO_INT_ENABLE_0, 0); + /* Disable enable interrupt flag */ + proc_thermal_mmio_write(pci_info, PROC_THERMAL_MMIO_INT_ENABLE_0, 0); + schedule_delayed_work(&pci_info->work, ms); + } pci_write_config_byte(pci_info->pdev, 0xdc, 0x01); - pkg_thermal_schedule_work(&pci_info->work); - - return IRQ_HANDLED; + return ret; } static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp) @@ -269,7 +282,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_ } ret = devm_request_threaded_irq(&pdev->dev, irq, - proc_thermal_irq_handler, NULL, + proc_thermal_irq_handler, proc_thermal_irq_thread_handler, irq_flag, KBUILD_MODNAME, pci_info); if (ret) { dev_err(&pdev->dev, "Request IRQ %d failed\n", pdev->irq); @@ -383,6 +396,8 @@ static struct pci_driver proc_thermal_pci_driver = { module_pci_driver(proc_thermal_pci_driver); +MODULE_IMPORT_NS(INT340X_THERMAL); + MODULE_AUTHOR("Srinivas Pandruvada "); MODULE_DESCRIPTION("Processor Thermal Reporting Device Driver"); MODULE_LICENSE("GPL v2"); From patchwork Tue Jun 20 23:01:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 110712 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4005871vqr; Tue, 20 Jun 2023 16:34:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7EJ3zncSm1RCkxHA3KI3/IKyW3IM/ubjPMkb/+IF1b06WPw2BV4fDT974XCQ4b3Hk2Y7/K X-Received: by 2002:a05:6e02:6c7:b0:342:623b:f45c with SMTP id p7-20020a056e0206c700b00342623bf45cmr8721683ils.9.1687304076316; Tue, 20 Jun 2023 16:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687304076; cv=none; d=google.com; s=arc-20160816; b=Gr7osh6CNRzG82wUHNXiOQgOrp5OJUxatcjb1FDPaHOuDXrrkKXOHOtsL1tLbKcbkc xMSRceE+78pRUzqZ+sQz2LaFcQdU9uM58qhvhe8RoPIkvVgBckoFpEN8MpEFGQH/HcK0 WSlHjWzCxKjZ4cGkQs0+2+k838EIoJVS01/JAdGOIOQQaNJqzLUtHIUnsX+vWfz3sWvm +48qCkZQr1/U0gnwI42aJTQyl5UPw/iT2imULt8IUQWMCj/ruO1C9O6OYx66bccAGTa+ Z3DWqnUxgiDgkqNyx/MOMSl9DUmVVeY1U+YWHlEEAbWwcOCIW2gvTddZhCJInybmw4JT d5LA== 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; bh=JHZU23vBQQshaDQWKRaUsKfaJvnQnKHaGvavNx4qh18=; b=j4Tbr0CNG260pV5Ha/aknmiuOZWhvpEdfb+U3v8Mme4CngiAhXMI657iC7E0Efy5LG rW/tHEWh1r55OtiogWoAo4bk8ZYQPJ6VyWyids3fAmBg0gM2mSTuBsgCXl7qvBo5ZyLH yvjVKawaw50tTE75oMHYyclAK+XgQVkmeuVKiNzGb+Dz791qJe/O4imSowqt/JtJq6h4 tj1DtFoYEVsW8AZCS5WEa5SiUpxEOfG81g5VisjLqel252rIZoBGNSKEnshNPKV3poMy 2HCr/V7FiZIOPuWrYXS1D2xMzCPlXl5f2LqDrlkuDESWwnfwtk/+FwFKPVc2OHsqOM/+ 8aIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="MBxu0Dx/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id om17-20020a17090b3a9100b002473e331f90si2941746pjb.46.2023.06.20.16.34.21; Tue, 20 Jun 2023 16:34:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="MBxu0Dx/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230088AbjFTXCZ (ORCPT + 99 others); Tue, 20 Jun 2023 19:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230027AbjFTXB6 (ORCPT ); Tue, 20 Jun 2023 19:01:58 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2191219B; Tue, 20 Jun 2023 16:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687302117; x=1718838117; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xOPnzUp7CuyZvBUd8tWM9+6hiuInfL7osBFcWmep3ps=; b=MBxu0Dx/VUkKp4R3Rvvzj87gxGZTqQNnDnNp4FtuM7L5seGwC1oCiReQ vb5DMq+HZKlqHw2yViDdxsOn0utIUd032tH0U447jZCieUrZdvJuwuhbS PTsVFj6kCP9KTXfjSl2B1IIgepkXVTozlNb5yrONwRjXiOM0+h6/L6i4+ 0av8JZ/Kkolg5zxY6pp51o2qs3V83B/HyeeEwO0wPW9nOGl31wkiRimcv htcdwM1kFIw2VuZLfTne1gqAbCXdIMCg+r3+5iIefZcEfjdA8T8Kp5et8 h94AUY3Z9wTRYCN9vro+SKKZEIAjYlbzRJjIJ+cCekJJIXt9uRP++DZFH Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="340347306" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="340347306" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 16:01:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="1044465342" X-IronPort-AV: E=Sophos;i="6.00,258,1681196400"; d="scan'208";a="1044465342" Received: from spandruv-desk.jf.intel.com ([10.54.75.8]) by fmsmga005.fm.intel.com with ESMTP; 20 Jun 2023 16:01:55 -0700 From: Srinivas Pandruvada To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH 7/7] selftests/thermel/intel: Add test to read workload hint Date: Tue, 20 Jun 2023 16:01:50 -0700 Message-Id: <20230620230150.3068704-8-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> References: <20230620230150.3068704-1-srinivas.pandruvada@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769266558656032029?= X-GMAIL-MSGID: =?utf-8?q?1769266558656032029?= Some SoCs have in built firmware support to classify current running workload and pass to OS for making power management decisions. This test program waits for notification of workload type change and prints. This program can be used to test this feature and also allows other user space programs to use as a reference. Signed-off-by: Srinivas Pandruvada --- .../testing/selftests/thermal/intel/Makefile | 16 +++ .../thermal/intel/workload_hint_test.c | 114 ++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 tools/testing/selftests/thermal/intel/Makefile create mode 100644 tools/testing/selftests/thermal/intel/workload_hint_test.c diff --git a/tools/testing/selftests/thermal/intel/Makefile b/tools/testing/selftests/thermal/intel/Makefile new file mode 100644 index 000000000000..02459e271ef7 --- /dev/null +++ b/tools/testing/selftests/thermal/intel/Makefile @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 +ifndef CROSS_COMPILE +uname_M := $(shell uname -m 2>/dev/null || echo not) +ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) + +ifeq ($(ARCH),x86) +TEST_PROGS := workload_hint_test + +all: $(TEST_PROGS) + +include ../../lib.mk + +clean: + rm -fr $(TEST_PROGS) +endif +endif diff --git a/tools/testing/selftests/thermal/intel/workload_hint_test.c b/tools/testing/selftests/thermal/intel/workload_hint_test.c new file mode 100644 index 000000000000..69a48a8ccbb4 --- /dev/null +++ b/tools/testing/selftests/thermal/intel/workload_hint_test.c @@ -0,0 +1,114 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include + +#define WORKLOAD_NOTIFICATION_DELAY_ATTRIBUTE "/sys/bus/pci/devices/0000:00:04.0/workload_hint/notification_delay_ms" +#define WORKLOAD_ENABLE_ATTRIBUTE "/sys/bus/pci/devices/0000:00:04.0/workload_hint/workload_hint_enable" +#define WORKLOAD_TYPE_INDEX_ATTRIBUTE "/sys/bus/pci/devices/0000:00:04.0/workload_hint/workload_type_index" + +static const char * const workload_types[] = { + "idle", + "battery_life", + "sustained", + "bursty", + NULL +}; + +#define WORKLOAD_TYPE_MAX_INDEX 3 + +int main(int argc, char **argv) { + struct pollfd ufd; + char index_str[4]; + int fd, ret, index; + int delay = 0; + + if (argc > 1) { + char delay_str[64]; + + sscanf(argv[1], "%d", &delay); + printf("Setting notification delay to %d ms\n", delay); + + if (delay < 0) + exit(1); + + sprintf(delay_str, "%s\n", argv[1]); + + if ((fd = open(WORKLOAD_NOTIFICATION_DELAY_ATTRIBUTE, O_RDWR)) < 0) { + perror("Unable to open workload notification delay\n"); + exit(1); + } + + if (write(fd, delay_str, strlen(delay_str)) < 0) { + perror("Can't set delay\n"); + exit(1); + } + + close(fd); + + } + + /* Enable feature via sysfs knob */ + if ((fd = open(WORKLOAD_ENABLE_ATTRIBUTE, O_RDWR)) < 0) { + perror("Unable to open workload type feature enable file\n"); + exit(1); + } + + if (write(fd, "1\n", 2) < 0) { + perror("Can' enable workload hints\n"); + exit(1); + } + + close(fd); + + while (1) { + if ((fd = open(WORKLOAD_TYPE_INDEX_ATTRIBUTE, O_RDONLY)) < 0) { + perror("Unable to open workload type file\n"); + exit(1); + } + + if ((lseek(fd, 0L, SEEK_SET)) < 0) { + fprintf(stderr, "Failed to set pointer to beginning\n"); + exit(1); + } + + if (read(fd, index_str, sizeof(index_str)) < 0) { + fprintf(stderr, "Failed to read from:%s\n", + WORKLOAD_TYPE_INDEX_ATTRIBUTE); + exit(1); + } + + ufd.fd = fd; + ufd.events = POLLPRI; + + if ((ret = poll(&ufd, 1, -1)) < 0) { + perror("poll error"); + exit(1); + } else if (ret == 0) { + printf("Poll Timeout\n"); + } else { + if ((lseek(fd, 0L, SEEK_SET)) < 0) { + fprintf(stderr, "Failed to set pointer to beginning\n"); + exit(1); + } + + if (read(fd, index_str, sizeof(index_str)) < 0) { + exit(0); + } + + sscanf(index_str, "%d", &index); + if (index > WORKLOAD_TYPE_MAX_INDEX) + printf("Invalid workload type index\n"); + else + printf("workload type:%s\n", workload_types[index]); + } + + close(fd); + } +}