|
| 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 <mario.limonciello@amd.com> |
| 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 | + /* https://gitlab.freedesktop.org/drm/amd/-/issues/2684 */ |
| 116 | + { |
| 117 | + .ident = "HP Laptop 15s-eq2xxx", |
| 118 | + .driver_data = &quirk_s2idle_bug, |
| 119 | + .matches = { |
| 120 | + DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 121 | + DMI_MATCH(DMI_PRODUCT_NAME, "HP Laptop 15s-eq2xxx"), |
| 122 | + } |
| 123 | + }, |
| 124 | + {} |
| 125 | +}; |
| 126 | + |
| 127 | +/* |
| 128 | + * Laptops that run a SMI handler during the D3->D0 transition that occurs |
| 129 | + * specifically when exiting suspend to idle which can cause |
| 130 | + * large delays during resume when the IOMMU translation layer is enabled (the default |
| 131 | + * behavior) for NVME devices: |
| 132 | + * |
| 133 | + * To avoid this firmware problem, skip the SMI handler on these machines before the |
| 134 | + * D0 transition occurs. |
| 135 | + */ |
| 136 | +static void amd_pmc_skip_nvme_smi_handler(u32 s2idle_bug_mmio) |
| 137 | +{ |
| 138 | + struct resource *res; |
| 139 | + void __iomem *addr; |
| 140 | + u8 val; |
| 141 | + |
| 142 | + res = request_mem_region_muxed(s2idle_bug_mmio, 1, "amd_pmc_pm80"); |
| 143 | + if (!res) |
| 144 | + return; |
| 145 | + |
| 146 | + addr = ioremap(s2idle_bug_mmio, 1); |
| 147 | + if (!addr) |
| 148 | + goto cleanup_resource; |
| 149 | + |
| 150 | + val = ioread8(addr); |
| 151 | + iowrite8(val & ~BIT(0), addr); |
| 152 | + |
| 153 | + iounmap(addr); |
| 154 | +cleanup_resource: |
| 155 | + release_resource(res); |
| 156 | + kfree(res); |
| 157 | +} |
| 158 | + |
| 159 | +void amd_pmc_process_restore_quirks(struct amd_pmc_dev *dev) |
| 160 | +{ |
| 161 | + if (dev->quirks && dev->quirks->s2idle_bug_mmio) |
| 162 | + amd_pmc_skip_nvme_smi_handler(dev->quirks->s2idle_bug_mmio); |
| 163 | +} |
| 164 | + |
| 165 | +void amd_pmc_quirks_init(struct amd_pmc_dev *dev) |
| 166 | +{ |
| 167 | + const struct dmi_system_id *dmi_id; |
| 168 | + |
| 169 | + dmi_id = dmi_first_match(fwbug_list); |
| 170 | + if (!dmi_id) |
| 171 | + return; |
| 172 | + dev->quirks = dmi_id->driver_data; |
| 173 | + if (dev->quirks->s2idle_bug_mmio) |
| 174 | + pr_info("Using s2idle quirk to avoid %s platform firmware bug\n", |
| 175 | + dmi_id->ident); |
| 176 | +} |
0 commit comments