Skip to content

Commit e8ef8dd

Browse files
superm1jwrdegoede
authored andcommitted
platform/x86: Move s2idle quirk from thinkpad-acpi to amd-pmc
It turns out that some-non Lenovo systems can benefit from the quirk introduced for Lenovo systems in commit 455cd86 ("platform/x86: thinkpad_acpi: Add a s2idle resume quirk for a number of laptops"). So move this quirk into running from the amd-pmc driver instead. No intended functional changes. Signed-off-by: Mario Limonciello <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent 9ecedaf commit e8ef8dd

File tree

5 files changed

+218
-167
lines changed

5 files changed

+218
-167
lines changed

drivers/platform/x86/amd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# AMD x86 Platform-Specific Drivers
55
#
66

7-
amd-pmc-y := pmc.o
7+
amd-pmc-y := pmc.o pmc-quirks.o
88
obj-$(CONFIG_AMD_PMC) += amd-pmc.o
99
amd_hsmp-y := hsmp.o
1010
obj-$(CONFIG_AMD_HSMP) += amd_hsmp.o

drivers/platform/x86/amd/pmc-quirks.c

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* AMD SoC Power Management Controller Driver Quirks
4+
*
5+
* Copyright (c) 2023, Advanced Micro Devices, Inc.
6+
* All Rights Reserved.
7+
*
8+
* Author: Mario Limonciello <[email protected]>
9+
*/
10+
11+
#include <linux/dmi.h>
12+
#include <linux/io.h>
13+
#include <linux/ioport.h>
14+
#include <linux/slab.h>
15+
16+
#include "pmc.h"
17+
18+
struct quirk_entry {
19+
u32 s2idle_bug_mmio;
20+
};
21+
22+
static struct quirk_entry quirk_s2idle_bug = {
23+
.s2idle_bug_mmio = 0xfed80380,
24+
};
25+
26+
static const struct dmi_system_id fwbug_list[] = {
27+
{
28+
.ident = "L14 Gen2 AMD",
29+
.driver_data = &quirk_s2idle_bug,
30+
.matches = {
31+
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
32+
DMI_MATCH(DMI_PRODUCT_NAME, "20X5"),
33+
}
34+
},
35+
{
36+
.ident = "T14s Gen2 AMD",
37+
.driver_data = &quirk_s2idle_bug,
38+
.matches = {
39+
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
40+
DMI_MATCH(DMI_PRODUCT_NAME, "20XF"),
41+
}
42+
},
43+
{
44+
.ident = "X13 Gen2 AMD",
45+
.driver_data = &quirk_s2idle_bug,
46+
.matches = {
47+
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
48+
DMI_MATCH(DMI_PRODUCT_NAME, "20XH"),
49+
}
50+
},
51+
{
52+
.ident = "T14 Gen2 AMD",
53+
.driver_data = &quirk_s2idle_bug,
54+
.matches = {
55+
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
56+
DMI_MATCH(DMI_PRODUCT_NAME, "20XK"),
57+
}
58+
},
59+
{
60+
.ident = "T14 Gen1 AMD",
61+
.driver_data = &quirk_s2idle_bug,
62+
.matches = {
63+
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
64+
DMI_MATCH(DMI_PRODUCT_NAME, "20UD"),
65+
}
66+
},
67+
{
68+
.ident = "T14 Gen1 AMD",
69+
.driver_data = &quirk_s2idle_bug,
70+
.matches = {
71+
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
72+
DMI_MATCH(DMI_PRODUCT_NAME, "20UE"),
73+
}
74+
},
75+
{
76+
.ident = "T14s Gen1 AMD",
77+
.driver_data = &quirk_s2idle_bug,
78+
.matches = {
79+
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
80+
DMI_MATCH(DMI_PRODUCT_NAME, "20UH"),
81+
}
82+
},
83+
{
84+
.ident = "T14s Gen1 AMD",
85+
.driver_data = &quirk_s2idle_bug,
86+
.matches = {
87+
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
88+
DMI_MATCH(DMI_PRODUCT_NAME, "20UJ"),
89+
}
90+
},
91+
{
92+
.ident = "P14s Gen1 AMD",
93+
.driver_data = &quirk_s2idle_bug,
94+
.matches = {
95+
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
96+
DMI_MATCH(DMI_PRODUCT_NAME, "20Y1"),
97+
}
98+
},
99+
{
100+
.ident = "P14s Gen2 AMD",
101+
.driver_data = &quirk_s2idle_bug,
102+
.matches = {
103+
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
104+
DMI_MATCH(DMI_PRODUCT_NAME, "21A0"),
105+
}
106+
},
107+
{
108+
.ident = "P14s Gen2 AMD",
109+
.driver_data = &quirk_s2idle_bug,
110+
.matches = {
111+
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
112+
DMI_MATCH(DMI_PRODUCT_NAME, "21A1"),
113+
}
114+
},
115+
{}
116+
};
117+
118+
/*
119+
* Laptops that run a SMI handler during the D3->D0 transition that occurs
120+
* specifically when exiting suspend to idle which can cause
121+
* large delays during resume when the IOMMU translation layer is enabled (the default
122+
* behavior) for NVME devices:
123+
*
124+
* To avoid this firmware problem, skip the SMI handler on these machines before the
125+
* D0 transition occurs.
126+
*/
127+
static void amd_pmc_skip_nvme_smi_handler(u32 s2idle_bug_mmio)
128+
{
129+
struct resource *res;
130+
void __iomem *addr;
131+
u8 val;
132+
133+
res = request_mem_region_muxed(s2idle_bug_mmio, 1, "amd_pmc_pm80");
134+
if (!res)
135+
return;
136+
137+
addr = ioremap(s2idle_bug_mmio, 1);
138+
if (!addr)
139+
goto cleanup_resource;
140+
141+
val = ioread8(addr);
142+
iowrite8(val & ~BIT(0), addr);
143+
144+
iounmap(addr);
145+
cleanup_resource:
146+
release_resource(res);
147+
kfree(res);
148+
}
149+
150+
void amd_pmc_process_restore_quirks(struct amd_pmc_dev *dev)
151+
{
152+
if (dev->quirks && dev->quirks->s2idle_bug_mmio)
153+
amd_pmc_skip_nvme_smi_handler(dev->quirks->s2idle_bug_mmio);
154+
}
155+
156+
void amd_pmc_quirks_init(struct amd_pmc_dev *dev)
157+
{
158+
const struct dmi_system_id *dmi_id;
159+
160+
dmi_id = dmi_first_match(fwbug_list);
161+
if (!dmi_id)
162+
return;
163+
dev->quirks = dmi_id->driver_data;
164+
if (dev->quirks->s2idle_bug_mmio)
165+
pr_info("Using s2idle quirk to avoid %s platform firmware bug\n",
166+
dmi_id->ident);
167+
}

drivers/platform/x86/amd/pmc.c

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <linux/seq_file.h>
2929
#include <linux/uaccess.h>
3030

31+
#include "pmc.h"
32+
3133
/* SMU communication registers */
3234
#define AMD_PMC_REGISTER_MESSAGE 0x538
3335
#define AMD_PMC_REGISTER_RESPONSE 0x980
@@ -146,29 +148,6 @@ static const struct amd_pmc_bit_map soc15_ip_blk[] = {
146148
{}
147149
};
148150

149-
struct amd_pmc_dev {
150-
void __iomem *regbase;
151-
void __iomem *smu_virt_addr;
152-
void __iomem *stb_virt_addr;
153-
void __iomem *fch_virt_addr;
154-
bool msg_port;
155-
u32 base_addr;
156-
u32 cpu_id;
157-
u32 active_ips;
158-
u32 dram_size;
159-
u32 num_ips;
160-
u32 s2d_msg_id;
161-
/* SMU version information */
162-
u8 smu_program;
163-
u8 major;
164-
u8 minor;
165-
u8 rev;
166-
struct device *dev;
167-
struct pci_dev *rdev;
168-
struct mutex lock; /* generic mutex lock */
169-
struct dentry *dbgfs_dir;
170-
};
171-
172151
static bool enable_stb;
173152
module_param(enable_stb, bool, 0644);
174153
MODULE_PARM_DESC(enable_stb, "Enable the STB debug mechanism");
@@ -891,6 +870,8 @@ static void amd_pmc_s2idle_restore(void)
891870

892871
/* Notify on failed entry */
893872
amd_pmc_validate_deepest(pdev);
873+
874+
amd_pmc_process_restore_quirks(pdev);
894875
}
895876

896877
static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = {
@@ -1087,6 +1068,8 @@ static int amd_pmc_probe(struct platform_device *pdev)
10871068
err = acpi_register_lps0_dev(&amd_pmc_s2idle_dev_ops);
10881069
if (err)
10891070
dev_warn(dev->dev, "failed to register LPS0 sleep handler, expect increased power consumption\n");
1071+
if (!disable_workarounds)
1072+
amd_pmc_quirks_init(dev);
10901073
}
10911074

10921075
amd_pmc_dbgfs_register(dev);

drivers/platform/x86/amd/pmc.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* AMD SoC Power Management Controller Driver
4+
*
5+
* Copyright (c) 2023, Advanced Micro Devices, Inc.
6+
* All Rights Reserved.
7+
*
8+
* Author: Mario Limonciello <[email protected]>
9+
*/
10+
11+
#ifndef PMC_H
12+
#define PMC_H
13+
14+
#include <linux/types.h>
15+
#include <linux/mutex.h>
16+
17+
struct amd_pmc_dev {
18+
void __iomem *regbase;
19+
void __iomem *smu_virt_addr;
20+
void __iomem *stb_virt_addr;
21+
void __iomem *fch_virt_addr;
22+
bool msg_port;
23+
u32 base_addr;
24+
u32 cpu_id;
25+
u32 active_ips;
26+
u32 dram_size;
27+
u32 num_ips;
28+
u32 s2d_msg_id;
29+
/* SMU version information */
30+
u8 smu_program;
31+
u8 major;
32+
u8 minor;
33+
u8 rev;
34+
struct device *dev;
35+
struct pci_dev *rdev;
36+
struct mutex lock; /* generic mutex lock */
37+
struct dentry *dbgfs_dir;
38+
struct quirk_entry *quirks;
39+
};
40+
41+
void amd_pmc_process_restore_quirks(struct amd_pmc_dev *dev);
42+
void amd_pmc_quirks_init(struct amd_pmc_dev *dev);
43+
44+
#endif /* PMC_H */

0 commit comments

Comments
 (0)