2023-06-13 15:53:44 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
2025-04-25 12:52:30 -07:00
|
|
|
* Intel PMC SSRAM TELEMETRY PCI Driver
|
2023-06-13 15:53:44 -07:00
|
|
|
*
|
|
|
|
* Copyright (c) 2023, Intel Corporation.
|
|
|
|
*/
|
|
|
|
|
2023-11-29 14:21:25 -08:00
|
|
|
#include <linux/cleanup.h>
|
2024-07-25 08:23:40 -04:00
|
|
|
#include <linux/intel_vsec.h>
|
2023-06-13 15:53:44 -07:00
|
|
|
#include <linux/pci.h>
|
2025-04-25 12:52:30 -07:00
|
|
|
#include <linux/types.h>
|
2023-06-13 15:53:44 -07:00
|
|
|
#include <linux/io-64-nonatomic-lo-hi.h>
|
|
|
|
|
|
|
|
#include "core.h"
|
2025-04-25 12:52:30 -07:00
|
|
|
#include "ssram_telemetry.h"
|
2023-06-13 15:53:44 -07:00
|
|
|
|
|
|
|
#define SSRAM_HDR_SIZE 0x100
|
|
|
|
#define SSRAM_PWRM_OFFSET 0x14
|
|
|
|
#define SSRAM_DVSEC_OFFSET 0x1C
|
|
|
|
#define SSRAM_DVSEC_SIZE 0x10
|
|
|
|
#define SSRAM_PCH_OFFSET 0x60
|
|
|
|
#define SSRAM_IOE_OFFSET 0x68
|
|
|
|
#define SSRAM_DEVID_OFFSET 0x70
|
|
|
|
|
2025-04-25 12:52:30 -07:00
|
|
|
DEFINE_FREE(pmc_ssram_telemetry_iounmap, void __iomem *, if (_T) iounmap(_T))
|
|
|
|
|
|
|
|
static struct pmc_ssram_telemetry *pmc_ssram_telems;
|
|
|
|
static bool device_probed;
|
2023-11-29 14:21:25 -08:00
|
|
|
|
2025-04-25 12:52:30 -07:00
|
|
|
static int
|
|
|
|
pmc_ssram_telemetry_add_pmt(struct pci_dev *pcidev, u64 ssram_base, void __iomem *ssram)
|
2023-11-29 14:21:27 -08:00
|
|
|
{
|
|
|
|
struct intel_vsec_platform_info info = {};
|
|
|
|
struct intel_vsec_header *headers[2] = {};
|
|
|
|
struct intel_vsec_header header;
|
|
|
|
void __iomem *dvsec;
|
|
|
|
u32 dvsec_offset;
|
|
|
|
u32 table, hdr;
|
|
|
|
|
|
|
|
dvsec_offset = readl(ssram + SSRAM_DVSEC_OFFSET);
|
|
|
|
dvsec = ioremap(ssram_base + dvsec_offset, SSRAM_DVSEC_SIZE);
|
|
|
|
if (!dvsec)
|
2025-04-25 12:52:30 -07:00
|
|
|
return -ENOMEM;
|
2023-11-29 14:21:27 -08:00
|
|
|
|
|
|
|
hdr = readl(dvsec + PCI_DVSEC_HEADER1);
|
|
|
|
header.id = readw(dvsec + PCI_DVSEC_HEADER2);
|
|
|
|
header.rev = PCI_DVSEC_HEADER1_REV(hdr);
|
|
|
|
header.length = PCI_DVSEC_HEADER1_LEN(hdr);
|
|
|
|
header.num_entries = readb(dvsec + INTEL_DVSEC_ENTRIES);
|
|
|
|
header.entry_size = readb(dvsec + INTEL_DVSEC_SIZE);
|
|
|
|
|
|
|
|
table = readl(dvsec + INTEL_DVSEC_TABLE);
|
|
|
|
header.tbir = INTEL_DVSEC_TABLE_BAR(table);
|
|
|
|
header.offset = INTEL_DVSEC_TABLE_OFFSET(table);
|
|
|
|
iounmap(dvsec);
|
|
|
|
|
|
|
|
headers[0] = &header;
|
|
|
|
info.caps = VSEC_CAP_TELEMETRY;
|
|
|
|
info.headers = headers;
|
|
|
|
info.base_addr = ssram_base;
|
2025-04-25 12:52:30 -07:00
|
|
|
info.parent = &pcidev->dev;
|
2023-11-29 14:21:27 -08:00
|
|
|
|
2025-04-25 12:52:30 -07:00
|
|
|
return intel_vsec_register(pcidev, &info);
|
2023-11-29 14:21:27 -08:00
|
|
|
}
|
|
|
|
|
2023-06-13 15:53:44 -07:00
|
|
|
static inline u64 get_base(void __iomem *addr, u32 offset)
|
|
|
|
{
|
|
|
|
return lo_hi_readq(addr + offset) & GENMASK_ULL(63, 3);
|
|
|
|
}
|
|
|
|
|
2023-11-29 14:21:25 -08:00
|
|
|
static int
|
2025-04-25 12:52:30 -07:00
|
|
|
pmc_ssram_telemetry_get_pmc(struct pci_dev *pcidev, unsigned int pmc_idx, u32 offset)
|
2023-06-13 15:53:44 -07:00
|
|
|
{
|
2025-04-25 12:52:30 -07:00
|
|
|
void __iomem __free(pmc_ssram_telemetry_iounmap) *tmp_ssram = NULL;
|
|
|
|
void __iomem __free(pmc_ssram_telemetry_iounmap) *ssram = NULL;
|
2023-11-29 14:21:25 -08:00
|
|
|
u64 ssram_base, pwrm_base;
|
2023-06-13 15:53:44 -07:00
|
|
|
u16 devid;
|
|
|
|
|
2025-04-25 12:52:30 -07:00
|
|
|
ssram_base = pci_resource_start(pcidev, 0);
|
2023-11-29 14:21:25 -08:00
|
|
|
tmp_ssram = ioremap(ssram_base, SSRAM_HDR_SIZE);
|
2024-10-18 16:19:58 +05:30
|
|
|
if (!tmp_ssram)
|
|
|
|
return -ENOMEM;
|
2023-06-13 15:53:44 -07:00
|
|
|
|
2023-11-29 14:21:25 -08:00
|
|
|
if (pmc_idx != PMC_IDX_MAIN) {
|
|
|
|
/*
|
|
|
|
* The secondary PMC BARS (which are behind hidden PCI devices)
|
|
|
|
* are read from fixed offsets in MMIO of the primary PMC BAR.
|
2025-01-06 09:46:52 -08:00
|
|
|
* If a device is not present, the value will be 0.
|
2023-11-29 14:21:25 -08:00
|
|
|
*/
|
|
|
|
ssram_base = get_base(tmp_ssram, offset);
|
2025-01-06 09:46:52 -08:00
|
|
|
if (!ssram_base)
|
|
|
|
return 0;
|
|
|
|
|
2023-06-13 15:53:44 -07:00
|
|
|
ssram = ioremap(ssram_base, SSRAM_HDR_SIZE);
|
|
|
|
if (!ssram)
|
2023-11-29 14:21:25 -08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ssram = no_free_ptr(tmp_ssram);
|
2023-06-13 15:53:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pwrm_base = get_base(ssram, SSRAM_PWRM_OFFSET);
|
|
|
|
devid = readw(ssram + SSRAM_DEVID_OFFSET);
|
|
|
|
|
2025-04-25 12:52:30 -07:00
|
|
|
pmc_ssram_telems[pmc_idx].devid = devid;
|
|
|
|
pmc_ssram_telems[pmc_idx].base_addr = pwrm_base;
|
|
|
|
|
2023-11-29 14:21:27 -08:00
|
|
|
/* Find and register and PMC telemetry entries */
|
2025-04-25 12:52:30 -07:00
|
|
|
return pmc_ssram_telemetry_add_pmt(pcidev, ssram_base, ssram);
|
|
|
|
}
|
2023-11-29 14:21:27 -08:00
|
|
|
|
2025-04-25 12:52:30 -07:00
|
|
|
/**
|
|
|
|
* pmc_ssram_telemetry_get_pmc_info() - Get a PMC devid and base_addr information
|
|
|
|
* @pmc_idx: Index of the PMC
|
|
|
|
* @pmc_ssram_telemetry: pmc_ssram_telemetry structure to store the PMC information
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* * 0 - Success
|
|
|
|
* * -EAGAIN - Probe function has not finished yet. Try again.
|
|
|
|
* * -EINVAL - Invalid pmc_idx
|
|
|
|
* * -ENODEV - PMC device is not available
|
|
|
|
*/
|
|
|
|
int pmc_ssram_telemetry_get_pmc_info(unsigned int pmc_idx,
|
|
|
|
struct pmc_ssram_telemetry *pmc_ssram_telemetry)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* PMCs are discovered in probe function. If this function is called before
|
|
|
|
* probe function complete, the result would be invalid. Use device_probed
|
|
|
|
* variable to avoid this case. Return -EAGAIN to inform the consumer to call
|
|
|
|
* again later.
|
|
|
|
*/
|
|
|
|
if (!device_probed)
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory barrier is used to ensure the correct read order between
|
|
|
|
* device_probed variable and PMC info.
|
|
|
|
*/
|
|
|
|
smp_rmb();
|
|
|
|
if (pmc_idx >= MAX_NUM_PMC)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!pmc_ssram_telems || !pmc_ssram_telems[pmc_idx].devid)
|
2023-11-29 14:21:25 -08:00
|
|
|
return -ENODEV;
|
2023-06-13 15:53:44 -07:00
|
|
|
|
2025-04-25 12:52:30 -07:00
|
|
|
pmc_ssram_telemetry->devid = pmc_ssram_telems[pmc_idx].devid;
|
|
|
|
pmc_ssram_telemetry->base_addr = pmc_ssram_telems[pmc_idx].base_addr;
|
|
|
|
return 0;
|
2023-06-13 15:53:44 -07:00
|
|
|
}
|
2025-04-25 12:52:30 -07:00
|
|
|
EXPORT_SYMBOL_GPL(pmc_ssram_telemetry_get_pmc_info);
|
2023-06-13 15:53:44 -07:00
|
|
|
|
2025-04-25 12:52:30 -07:00
|
|
|
static int intel_pmc_ssram_telemetry_probe(struct pci_dev *pcidev, const struct pci_device_id *id)
|
2023-06-13 15:53:44 -07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2025-04-25 12:52:30 -07:00
|
|
|
pmc_ssram_telems = devm_kzalloc(&pcidev->dev, sizeof(*pmc_ssram_telems) * MAX_NUM_PMC,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!pmc_ssram_telems) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto probe_finish;
|
|
|
|
}
|
2023-06-13 15:53:44 -07:00
|
|
|
|
|
|
|
ret = pcim_enable_device(pcidev);
|
2025-04-25 12:52:30 -07:00
|
|
|
if (ret) {
|
|
|
|
dev_dbg(&pcidev->dev, "failed to enable PMC SSRAM device\n");
|
|
|
|
goto probe_finish;
|
|
|
|
}
|
2023-06-13 15:53:44 -07:00
|
|
|
|
2025-04-25 12:52:30 -07:00
|
|
|
ret = pmc_ssram_telemetry_get_pmc(pcidev, PMC_IDX_MAIN, 0);
|
2023-11-29 14:21:25 -08:00
|
|
|
if (ret)
|
2025-04-25 12:52:30 -07:00
|
|
|
goto probe_finish;
|
|
|
|
|
|
|
|
pmc_ssram_telemetry_get_pmc(pcidev, PMC_IDX_IOE, SSRAM_IOE_OFFSET);
|
|
|
|
pmc_ssram_telemetry_get_pmc(pcidev, PMC_IDX_PCH, SSRAM_PCH_OFFSET);
|
|
|
|
|
|
|
|
probe_finish:
|
|
|
|
/*
|
|
|
|
* Memory barrier is used to ensure the correct write order between PMC info
|
|
|
|
* and device_probed variable.
|
|
|
|
*/
|
|
|
|
smp_wmb();
|
|
|
|
device_probed = true;
|
2023-11-29 14:21:24 -08:00
|
|
|
return ret;
|
2023-06-13 15:53:44 -07:00
|
|
|
}
|
2025-04-25 12:52:30 -07:00
|
|
|
|
|
|
|
static const struct pci_device_id intel_pmc_ssram_telemetry_pci_ids[] = {
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PMC_DEVID_MTL_SOCM) },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PMC_DEVID_ARL_SOCS) },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PMC_DEVID_ARL_SOCM) },
|
2025-06-10 16:04:06 -07:00
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PMC_DEVID_LNL_SOCM) },
|
2025-06-10 16:04:07 -07:00
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PMC_DEVID_PTL_PCDH) },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PMC_DEVID_PTL_PCDP) },
|
2025-04-25 12:52:30 -07:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, intel_pmc_ssram_telemetry_pci_ids);
|
|
|
|
|
|
|
|
static struct pci_driver intel_pmc_ssram_telemetry_driver = {
|
|
|
|
.name = "intel_pmc_ssram_telemetry",
|
|
|
|
.id_table = intel_pmc_ssram_telemetry_pci_ids,
|
|
|
|
.probe = intel_pmc_ssram_telemetry_probe,
|
|
|
|
};
|
|
|
|
module_pci_driver(intel_pmc_ssram_telemetry_driver);
|
|
|
|
|
module: Convert symbol namespace to string literal
Clean up the existing export namespace code along the same lines of
commit 33def8498fdd ("treewide: Convert macro and uses of __section(foo)
to __section("foo")") and for the same reason, it is not desired for the
namespace argument to be a macro expansion itself.
Scripted using
git grep -l -e MODULE_IMPORT_NS -e EXPORT_SYMBOL_NS | while read file;
do
awk -i inplace '
/^#define EXPORT_SYMBOL_NS/ {
gsub(/__stringify\(ns\)/, "ns");
print;
next;
}
/^#define MODULE_IMPORT_NS/ {
gsub(/__stringify\(ns\)/, "ns");
print;
next;
}
/MODULE_IMPORT_NS/ {
$0 = gensub(/MODULE_IMPORT_NS\(([^)]*)\)/, "MODULE_IMPORT_NS(\"\\1\")", "g");
}
/EXPORT_SYMBOL_NS/ {
if ($0 ~ /(EXPORT_SYMBOL_NS[^(]*)\(([^,]+),/) {
if ($0 !~ /(EXPORT_SYMBOL_NS[^(]*)\(([^,]+), ([^)]+)\)/ &&
$0 !~ /(EXPORT_SYMBOL_NS[^(]*)\(\)/ &&
$0 !~ /^my/) {
getline line;
gsub(/[[:space:]]*\\$/, "");
gsub(/[[:space:]]/, "", line);
$0 = $0 " " line;
}
$0 = gensub(/(EXPORT_SYMBOL_NS[^(]*)\(([^,]+), ([^)]+)\)/,
"\\1(\\2, \"\\3\")", "g");
}
}
{ print }' $file;
done
Requested-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://mail.google.com/mail/u/2/#inbox/FMfcgzQXKWgMmjdFwwdsfgxzKpVHWPlc
Acked-by: Greg KH <gregkh@linuxfoundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2024-12-02 15:59:47 +01:00
|
|
|
MODULE_IMPORT_NS("INTEL_VSEC");
|
2025-04-25 12:52:30 -07:00
|
|
|
MODULE_AUTHOR("Xi Pardee <xi.pardee@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("Intel PMC SSRAM Telemetry driver");
|
|
|
|
MODULE_LICENSE("GPL");
|