Skip to content

Commit dd28a3c

Browse files
spandruvadarafaeljw
authored andcommitted
thermal: int340x: processor_thermal: Add interrupt configuration function
Some features like workload type prediction and power floor events require interrupt support to avoid polling. Here interrupts are enabled and 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 involves 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 callers: processor_thermal_send_mbox_[read|write]_cmd(). Signed-off-by: Srinivas Pandruvada <[email protected]> [ rjw: Adjust subject, fix up computation ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent b894685 commit dd28a3c

File tree

2 files changed

+68
-19
lines changed

2 files changed

+68
-19
lines changed

drivers/thermal/intel/int340x_thermal/processor_thermal_device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ void proc_thermal_wt_req_remove(struct pci_dev *pdev);
9191

9292
int processor_thermal_send_mbox_read_cmd(struct pci_dev *pdev, u16 id, u64 *resp);
9393
int processor_thermal_send_mbox_write_cmd(struct pci_dev *pdev, u16 id, u32 data);
94+
int processor_thermal_mbox_interrupt_config(struct pci_dev *pdev, bool enable, int enable_bit,
95+
int time_window);
9496
int proc_thermal_add(struct device *dev, struct proc_thermal_device *priv);
9597
void proc_thermal_remove(struct proc_thermal_device *proc_priv);
9698
int proc_thermal_suspend(struct device *dev);

drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,16 @@ static int send_mbox_write_cmd(struct pci_dev *pdev, u16 id, u32 data)
4545
int ret;
4646

4747
proc_priv = pci_get_drvdata(pdev);
48-
49-
mutex_lock(&mbox_lock);
50-
5148
ret = wait_for_mbox_ready(proc_priv);
5249
if (ret)
53-
goto unlock_mbox;
50+
return ret;
5451

5552
writel(data, (proc_priv->mmio_base + MBOX_OFFSET_DATA));
5653
/* Write command register */
5754
reg_data = BIT_ULL(MBOX_BUSY_BIT) | id;
5855
writel(reg_data, (proc_priv->mmio_base + MBOX_OFFSET_INTERFACE));
5956

60-
ret = wait_for_mbox_ready(proc_priv);
61-
62-
unlock_mbox:
63-
mutex_unlock(&mbox_lock);
64-
return ret;
57+
return wait_for_mbox_ready(proc_priv);
6558
}
6659

6760
static int send_mbox_read_cmd(struct pci_dev *pdev, u16 id, u64 *resp)
@@ -71,41 +64,95 @@ static int send_mbox_read_cmd(struct pci_dev *pdev, u16 id, u64 *resp)
7164
int ret;
7265

7366
proc_priv = pci_get_drvdata(pdev);
74-
75-
mutex_lock(&mbox_lock);
76-
7767
ret = wait_for_mbox_ready(proc_priv);
7868
if (ret)
79-
goto unlock_mbox;
69+
return ret;
8070

8171
/* Write command register */
8272
reg_data = BIT_ULL(MBOX_BUSY_BIT) | id;
8373
writel(reg_data, (proc_priv->mmio_base + MBOX_OFFSET_INTERFACE));
8474

8575
ret = wait_for_mbox_ready(proc_priv);
8676
if (ret)
87-
goto unlock_mbox;
77+
return ret;
8878

8979
if (id == MBOX_CMD_WORKLOAD_TYPE_READ)
9080
*resp = readl(proc_priv->mmio_base + MBOX_OFFSET_DATA);
9181
else
9282
*resp = readq(proc_priv->mmio_base + MBOX_OFFSET_DATA);
9383

94-
unlock_mbox:
95-
mutex_unlock(&mbox_lock);
96-
return ret;
84+
return 0;
9785
}
9886

9987
int processor_thermal_send_mbox_read_cmd(struct pci_dev *pdev, u16 id, u64 *resp)
10088
{
101-
return send_mbox_read_cmd(pdev, id, resp);
89+
int ret;
90+
91+
mutex_lock(&mbox_lock);
92+
ret = send_mbox_read_cmd(pdev, id, resp);
93+
mutex_unlock(&mbox_lock);
94+
95+
return ret;
10296
}
10397
EXPORT_SYMBOL_NS_GPL(processor_thermal_send_mbox_read_cmd, INT340X_THERMAL);
10498

10599
int processor_thermal_send_mbox_write_cmd(struct pci_dev *pdev, u16 id, u32 data)
106100
{
107-
return send_mbox_write_cmd(pdev, id, data);
101+
int ret;
102+
103+
mutex_lock(&mbox_lock);
104+
ret = send_mbox_write_cmd(pdev, id, data);
105+
mutex_unlock(&mbox_lock);
106+
107+
return ret;
108108
}
109109
EXPORT_SYMBOL_NS_GPL(processor_thermal_send_mbox_write_cmd, INT340X_THERMAL);
110110

111+
#define MBOX_CAMARILLO_RD_INTR_CONFIG 0x1E
112+
#define MBOX_CAMARILLO_WR_INTR_CONFIG 0x1F
113+
#define WLT_TW_MASK GENMASK_ULL(30, 24)
114+
#define SOC_PREDICTION_TW_SHIFT 24
115+
116+
int processor_thermal_mbox_interrupt_config(struct pci_dev *pdev, bool enable,
117+
int enable_bit, int time_window)
118+
{
119+
u64 data;
120+
int ret;
121+
122+
if (!pdev)
123+
return -ENODEV;
124+
125+
mutex_lock(&mbox_lock);
126+
127+
/* Do read modify write for MBOX_CAMARILLO_RD_INTR_CONFIG */
128+
129+
ret = send_mbox_read_cmd(pdev, MBOX_CAMARILLO_RD_INTR_CONFIG, &data);
130+
if (ret) {
131+
dev_err(&pdev->dev, "MBOX_CAMARILLO_RD_INTR_CONFIG failed\n");
132+
goto unlock;
133+
}
134+
135+
if (time_window >= 0) {
136+
data &= ~WLT_TW_MASK;
137+
138+
/* Program notification delay */
139+
data |= ((u64)time_window << SOC_PREDICTION_TW_SHIFT) & WLT_TW_MASK;
140+
}
141+
142+
if (enable)
143+
data |= BIT(enable_bit);
144+
else
145+
data &= ~BIT(enable_bit);
146+
147+
ret = send_mbox_write_cmd(pdev, MBOX_CAMARILLO_WR_INTR_CONFIG, data);
148+
if (ret)
149+
dev_err(&pdev->dev, "MBOX_CAMARILLO_WR_INTR_CONFIG failed\n");
150+
151+
unlock:
152+
mutex_unlock(&mbox_lock);
153+
154+
return ret;
155+
}
156+
EXPORT_SYMBOL_NS_GPL(processor_thermal_mbox_interrupt_config, INT340X_THERMAL);
157+
111158
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)