forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x86/amd_nb: Move SMN access code to a new amd_node driver
SMN access was bolted into amd_nb mostly as convenience. This has limitations though that require incurring tech debt to keep it working. Move SMN access to the newly introduced AMD Node driver. Signed-off-by: Mario Limonciello <[email protected]> Signed-off-by: Yazen Ghannam <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Acked-by: Ilpo Järvinen <[email protected]> # pdx86 Acked-by: Shyam Sundar S K <[email protected]> # PMF, PMC Link: https://lore.kernel.org/r/[email protected]
- Loading branch information
Showing
16 changed files
with
107 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1122,6 +1122,7 @@ S: Supported | |
F: drivers/i2c/busses/i2c-amd-asf-plat.c | ||
|
||
AMD NODE DRIVER | ||
M: Mario Limonciello <[email protected]> | ||
M: Yazen Ghannam <[email protected]> | ||
L: [email protected] | ||
S: Supported | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
* Author: Yazen Ghannam <[email protected]> | ||
*/ | ||
|
||
#include <asm/amd_nb.h> | ||
#include <asm/amd_node.h> | ||
|
||
/* | ||
|
@@ -88,3 +89,92 @@ struct pci_dev *amd_node_get_root(u16 node) | |
pci_dbg(root, "is root for AMD node %u\n", node); | ||
return root; | ||
} | ||
|
||
/* Protect the PCI config register pairs used for SMN. */ | ||
static DEFINE_MUTEX(smn_mutex); | ||
|
||
/* | ||
* SMN accesses may fail in ways that are difficult to detect here in the called | ||
* functions amd_smn_read() and amd_smn_write(). Therefore, callers must do | ||
* their own checking based on what behavior they expect. | ||
* | ||
* For SMN reads, the returned value may be zero if the register is Read-as-Zero. | ||
* Or it may be a "PCI Error Response", e.g. all 0xFFs. The "PCI Error Response" | ||
* can be checked here, and a proper error code can be returned. | ||
* | ||
* But the Read-as-Zero response cannot be verified here. A value of 0 may be | ||
* correct in some cases, so callers must check that this correct is for the | ||
* register/fields they need. | ||
* | ||
* For SMN writes, success can be determined through a "write and read back" | ||
* However, this is not robust when done here. | ||
* | ||
* Possible issues: | ||
* | ||
* 1) Bits that are "Write-1-to-Clear". In this case, the read value should | ||
* *not* match the write value. | ||
* | ||
* 2) Bits that are "Read-as-Zero"/"Writes-Ignored". This information cannot be | ||
* known here. | ||
* | ||
* 3) Bits that are "Reserved / Set to 1". Ditto above. | ||
* | ||
* Callers of amd_smn_write() should do the "write and read back" check | ||
* themselves, if needed. | ||
* | ||
* For #1, they can see if their target bits got cleared. | ||
* | ||
* For #2 and #3, they can check if their target bits got set as intended. | ||
* | ||
* This matches what is done for RDMSR/WRMSR. As long as there's no #GP, then | ||
* the operation is considered a success, and the caller does their own | ||
* checking. | ||
*/ | ||
static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write) | ||
{ | ||
struct pci_dev *root; | ||
int err = -ENODEV; | ||
|
||
if (node >= amd_nb_num()) | ||
goto out; | ||
|
||
root = node_to_amd_nb(node)->root; | ||
if (!root) | ||
goto out; | ||
|
||
mutex_lock(&smn_mutex); | ||
|
||
err = pci_write_config_dword(root, 0x60, address); | ||
if (err) { | ||
pr_warn("Error programming SMN address 0x%x.\n", address); | ||
goto out_unlock; | ||
} | ||
|
||
err = (write ? pci_write_config_dword(root, 0x64, *value) | ||
: pci_read_config_dword(root, 0x64, value)); | ||
|
||
out_unlock: | ||
mutex_unlock(&smn_mutex); | ||
|
||
out: | ||
return err; | ||
} | ||
|
||
int __must_check amd_smn_read(u16 node, u32 address, u32 *value) | ||
{ | ||
int err = __amd_smn_rw(node, address, value, false); | ||
|
||
if (PCI_POSSIBLE_ERROR(*value)) { | ||
err = -ENODEV; | ||
*value = 0; | ||
} | ||
|
||
return err; | ||
} | ||
EXPORT_SYMBOL_GPL(amd_smn_read); | ||
|
||
int __must_check amd_smn_write(u16 node, u32 address, u32 value) | ||
{ | ||
return __amd_smn_rw(node, address, &value, true); | ||
} | ||
EXPORT_SYMBOL_GPL(amd_smn_write); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,13 @@ | |
* Author: Shyam Sundar S K <[email protected]> | ||
*/ | ||
|
||
#include <asm/amd_nb.h> | ||
#include <linux/debugfs.h> | ||
#include <linux/iopoll.h> | ||
#include <linux/module.h> | ||
#include <linux/pci.h> | ||
#include <linux/platform_device.h> | ||
#include <linux/power_supply.h> | ||
#include <asm/amd_node.h> | ||
#include "pmf.h" | ||
|
||
/* PMF-SMU communication registers */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#include <linux/ras.h> | ||
|
||
#include <asm/amd_nb.h> | ||
#include <asm/amd_node.h> | ||
|
||
#include "reg_fields.h" | ||
|
||
|