1 // SPDX-License-Identifier: GPL-2.0-only
3 * Processor thermal device module for registering and processing
4 * power floor. When the hardware reduces the power to the minimum
5 * possible, the power floor is notified via an interrupt.
8 * When user space enables power floor reporting:
10 * Enable processor thermal device interrupt
12 * - Current status of power floor is read from offset 0x5B18
15 * Two interface functions are provided to call when there is a
16 * thermal device interrupt:
17 * - proc_thermal_power_floor_intr():
18 * Check if the interrupt is for change in power floor.
19 * Called from interrupt context.
21 * - proc_thermal_power_floor_intr_callback():
22 * Callback for interrupt processing in thread context. This involves
23 * sending notification to user space that there is a change in the
26 * Copyright (c) 2023, Intel Corporation.
29 #include <linux/pci.h>
30 #include "processor_thermal_device.h"
32 #define SOC_POWER_FLOOR_STATUS BIT(39)
33 #define SOC_POWER_FLOOR_SHIFT 39
35 #define SOC_POWER_FLOOR_INT_ENABLE_BIT 31
36 #define SOC_POWER_FLOOR_INT_ACTIVE BIT(3)
38 int proc_thermal_read_power_floor_status(struct proc_thermal_device *proc_priv)
42 status = readq(proc_priv->mmio_base + SOC_WT_RES_INT_STATUS_OFFSET);
43 return (status & SOC_POWER_FLOOR_STATUS) >> SOC_POWER_FLOOR_SHIFT;
45 EXPORT_SYMBOL_NS_GPL(proc_thermal_read_power_floor_status, "INT340X_THERMAL");
47 static bool enable_state;
48 static DEFINE_MUTEX(pf_lock);
50 int proc_thermal_power_floor_set_state(struct proc_thermal_device *proc_priv, bool enable)
55 if (enable_state == enable)
59 * Time window parameter is not applicable to power floor interrupt configuration.
60 * Hence use -1 for time window.
62 ret = processor_thermal_mbox_interrupt_config(to_pci_dev(proc_priv->dev), enable,
63 SOC_POWER_FLOOR_INT_ENABLE_BIT, -1);
65 enable_state = enable;
68 mutex_unlock(&pf_lock);
72 EXPORT_SYMBOL_NS_GPL(proc_thermal_power_floor_set_state, "INT340X_THERMAL");
74 bool proc_thermal_power_floor_get_state(struct proc_thermal_device *proc_priv)
78 EXPORT_SYMBOL_NS_GPL(proc_thermal_power_floor_get_state, "INT340X_THERMAL");
81 * proc_thermal_check_power_floor_intr() - Check power floor interrupt.
82 * @proc_priv: Processor thermal device instance.
84 * Callback to check if the interrupt for power floor is active.
86 * Context: Called from interrupt context.
88 * Return: true if power floor is active, false when not active.
90 bool proc_thermal_check_power_floor_intr(struct proc_thermal_device *proc_priv)
94 int_status = readq(proc_priv->mmio_base + SOC_WT_RES_INT_STATUS_OFFSET);
95 return !!(int_status & SOC_POWER_FLOOR_INT_ACTIVE);
97 EXPORT_SYMBOL_NS_GPL(proc_thermal_check_power_floor_intr, "INT340X_THERMAL");
100 * proc_thermal_power_floor_intr_callback() - Process power floor notification
101 * @pdev: PCI device instance
102 * @proc_priv: Processor thermal device instance.
104 * Check if the power floor interrupt is active, if active send notification to
105 * user space for the attribute "power_limits", so that user can read the attribute
108 * Context: Called from interrupt thread context.
112 void proc_thermal_power_floor_intr_callback(struct pci_dev *pdev,
113 struct proc_thermal_device *proc_priv)
117 status = readq(proc_priv->mmio_base + SOC_WT_RES_INT_STATUS_OFFSET);
118 if (!(status & SOC_POWER_FLOOR_INT_ACTIVE))
121 sysfs_notify(&pdev->dev.kobj, "power_limits", "power_floor_status");
123 EXPORT_SYMBOL_NS_GPL(proc_thermal_power_floor_intr_callback, "INT340X_THERMAL");
125 MODULE_IMPORT_NS("INT340X_THERMAL");
126 MODULE_LICENSE("GPL");
127 MODULE_DESCRIPTION("Processor Thermal power floor notification Interface");