Skip to content

Commit 045a513

Browse files
debox1jwrdegoede
authored andcommitted
platform/x86/intel/pmt: Use PMT callbacks
PMT providers may require device specific actions before their telemetry may be read. If the read_telem() is assigned, call it instead of memcpy_fromio() and return. Since this needs to be done in multiple locations, add pmt_telem_read_mmio() as a wrapper function to perform this and any other needed checks. Reviewed-by: Ilpo Järvinen <[email protected]> Reviewed-by: Michael J. Ruhl <[email protected]> Signed-off-by: David E. Box <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans de Goede <[email protected]>
1 parent e92affc commit 045a513

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

drivers/platform/x86/intel/pmt/class.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ pmt_memcpy64_fromio(void *to, const u64 __iomem *from, size_t count)
5858
return count;
5959
}
6060

61+
int pmt_telem_read_mmio(struct pci_dev *pdev, struct pmt_callbacks *cb, u32 guid, void *buf,
62+
void __iomem *addr, u32 count)
63+
{
64+
if (cb && cb->read_telem)
65+
return cb->read_telem(pdev, guid, buf, count);
66+
67+
if (guid == GUID_SPR_PUNIT)
68+
/* PUNIT on SPR only supports aligned 64-bit read */
69+
return pmt_memcpy64_fromio(buf, addr, count);
70+
71+
memcpy_fromio(buf, addr, count);
72+
73+
return count;
74+
}
75+
EXPORT_SYMBOL_NS_GPL(pmt_telem_read_mmio, INTEL_PMT);
76+
6177
/*
6278
* sysfs
6379
*/
@@ -79,11 +95,8 @@ intel_pmt_read(struct file *filp, struct kobject *kobj,
7995
if (count > entry->size - off)
8096
count = entry->size - off;
8197

82-
if (entry->guid == GUID_SPR_PUNIT)
83-
/* PUNIT on SPR only supports aligned 64-bit read */
84-
count = pmt_memcpy64_fromio(buf, entry->base + off, count);
85-
else
86-
memcpy_fromio(buf, entry->base + off, count);
98+
count = pmt_telem_read_mmio(entry->ep->pcidev, entry->cb, entry->header.guid, buf,
99+
entry->base + off, count);
87100

88101
return count;
89102
}
@@ -239,6 +252,7 @@ static int intel_pmt_populate_entry(struct intel_pmt_entry *entry,
239252

240253
entry->guid = header->guid;
241254
entry->size = header->size;
255+
entry->cb = ivdev->priv_data;
242256

243257
return 0;
244258
}
@@ -300,7 +314,7 @@ static int intel_pmt_dev_register(struct intel_pmt_entry *entry,
300314
goto fail_ioremap;
301315

302316
if (ns->pmt_add_endpoint) {
303-
ret = ns->pmt_add_endpoint(entry, ivdev->pcidev);
317+
ret = ns->pmt_add_endpoint(ivdev, entry);
304318
if (ret)
305319
goto fail_add_endpoint;
306320
}

drivers/platform/x86/intel/pmt/class.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct pci_dev;
2424
struct telem_endpoint {
2525
struct pci_dev *pcidev;
2626
struct telem_header header;
27+
struct pmt_callbacks *cb;
2728
void __iomem *base;
2829
bool present;
2930
struct kref kref;
@@ -43,6 +44,7 @@ struct intel_pmt_entry {
4344
struct kobject *kobj;
4445
void __iomem *disc_table;
4546
void __iomem *base;
47+
struct pmt_callbacks *cb;
4648
unsigned long base_addr;
4749
size_t size;
4850
u32 guid;
@@ -55,10 +57,12 @@ struct intel_pmt_namespace {
5557
const struct attribute_group *attr_grp;
5658
int (*pmt_header_decode)(struct intel_pmt_entry *entry,
5759
struct device *dev);
58-
int (*pmt_add_endpoint)(struct intel_pmt_entry *entry,
59-
struct pci_dev *pdev);
60+
int (*pmt_add_endpoint)(struct intel_vsec_device *ivdev,
61+
struct intel_pmt_entry *entry);
6062
};
6163

64+
int pmt_telem_read_mmio(struct pci_dev *pdev, struct pmt_callbacks *cb, u32 guid, void *buf,
65+
void __iomem *addr, u32 count);
6266
bool intel_pmt_is_early_client_hw(struct device *dev);
6367
int intel_pmt_dev_create(struct intel_pmt_entry *entry,
6468
struct intel_pmt_namespace *ns,

drivers/platform/x86/intel/pmt/telemetry.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ static int pmt_telem_header_decode(struct intel_pmt_entry *entry,
9393
return 0;
9494
}
9595

96-
static int pmt_telem_add_endpoint(struct intel_pmt_entry *entry,
97-
struct pci_dev *pdev)
96+
static int pmt_telem_add_endpoint(struct intel_vsec_device *ivdev,
97+
struct intel_pmt_entry *entry)
9898
{
9999
struct telem_endpoint *ep;
100100

@@ -104,13 +104,14 @@ static int pmt_telem_add_endpoint(struct intel_pmt_entry *entry,
104104
return -ENOMEM;
105105

106106
ep = entry->ep;
107-
ep->pcidev = pdev;
107+
ep->pcidev = ivdev->pcidev;
108108
ep->header.access_type = entry->header.access_type;
109109
ep->header.guid = entry->header.guid;
110110
ep->header.base_offset = entry->header.base_offset;
111111
ep->header.size = entry->header.size;
112112
ep->base = entry->base;
113113
ep->present = true;
114+
ep->cb = ivdev->priv_data;
114115

115116
kref_init(&ep->kref);
116117

@@ -218,7 +219,8 @@ int pmt_telem_read(struct telem_endpoint *ep, u32 id, u64 *data, u32 count)
218219
if (offset + NUM_BYTES_QWORD(count) > size)
219220
return -EINVAL;
220221

221-
memcpy_fromio(data, ep->base + offset, NUM_BYTES_QWORD(count));
222+
pmt_telem_read_mmio(ep->pcidev, ep->cb, ep->header.guid, data, ep->base + offset,
223+
NUM_BYTES_QWORD(count));
222224

223225
return ep->present ? 0 : -EPIPE;
224226
}

0 commit comments

Comments
 (0)