platform/x86/intel: refactor endpoint usage
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v3 1/11 platform/x86/intel: refactor endpoint usage
The use of an endpoint has introduced a dependency in all class/pmt drivers to have an endpoint allocated.
The telemetry driver has this allocation, the crashlog does not.
The current usage is very telemetry focused, but should be common code.
With this in mind:
rename the struct telemetry_endpoint to struct class_endpoint, refactor the common endpoint code to be in the class.c module
--- drivers/platform/x86/intel/pmc/core.c | 3 +- drivers/platform/x86/intel/pmc/core.h | 4 +- drivers/platform/x86/intel/pmc/core_ssram.c | 2 +- drivers/platform/x86/intel/pmt/class.c | 45 ++++++++++++++++++ drivers/platform/x86/intel/pmt/class.h | 21 +++++++-- drivers/platform/x86/intel/pmt/telemetry.c | 51 ++++----------------- drivers/platform/x86/intel/pmt/telemetry.h | 23 ++++------ 7 files changed, 84 insertions(+), 65 deletions(-)
drivers/platform/x86/intel/pmc/core.c +2 -1
@@ -29,6 +29,7 @@#include <asm/tsc.h> #include "core.h" +#include "../pmt/class.h" #include "../pmt/telemetry.h" /* Maximum number of modes supported by platfoms that has low power mode capability */
@@ -1198,7 +1199,7 @@ int get_primary_reg_base(struct pmc *pmc)void pmc_core_punit_pmt_init (struct pmc_dev *pmcdev,u32 guid) { -struct telem_endpoint *ep; +struct class_endpoint *ep;struct pci_dev *pcidev; pcidev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (10 ,0 ));
drivers/platform/x86/intel/pmc/core.h +2 -2
@@ -16,7 +16,7 @@#include <linux/bits.h> #include <linux/platform_device.h> -struct telem_endpoint ; +struct class_endpoint ;#define SLP_S0_RES_COUNTER_MASK GENMASK(31, 0)
@@ -432,7 +432,7 @@ struct pmc_dev {bool has_die_c6;u32 die_c6_offset; -struct telem_endpoint *punit_ep; +struct class_endpoint *punit_ep;struct pmc_info *regmap_list; };
drivers/platform/x86/intel/pmc/core_ssram.c +1 -1
@@ -42,7 +42,7 @@ static u32 pmc_core_find_guid(struct pmc_info *list, const struct pmc_reg_map *mstatic int pmc_core_get_lpm_req (struct pmc_dev *pmcdev,struct pmc *pmc) { -struct telem_endpoint *ep; +struct class_endpoint *ep;const u8 *lpm_indices;int num_maps, mode_offset =0 ;int ret, mode;
drivers/platform/x86/intel/pmt/class.c +45 -0
57 lines not on this page · raw message
drivers/platform/x86/intel/pmt/class.h +16 -5
@@ -9,8 +9,6 @@#include <linux/err.h> #include <linux/io.h> -#include "telemetry.h" -/* PMT access types */ #define ACCESS_BARID 2#define ACCESS_LOCAL 3
@@ -19,11 +17,19 @@#define GET_BIR (v) ((v) & GENMASK(2, 0))#define GET_ADDRESS (v) ((v) & GENMASK(31, 3)) +struct kref ;struct pci_dev ; -struct telem_endpoint { +struct class_header { +u8 access_type; +u16 size; +u32 guid; +u32 base_offset; +}; + +struct class_endpoint {struct pci_dev *pcidev; -struct telem_header header; +struct class_header header;struct pmt_callbacks *cb;void __iomem *base;bool present;
@@ -38,7 +44,7 @@ struct intel_pmt_header { };struct intel_pmt_entry { -struct telem_endpoint *ep; +struct class_endpoint *ep;struct intel_pmt_header header;struct bin_attribute pmt_bin_attr;struct kobject *kobj;
@@ -69,4 +75,9 @@ int intel_pmt_dev_create(struct intel_pmt_entry *entry, struct intel_vsec_device *dev, int idx);void intel_pmt_dev_destroy (struct intel_pmt_entry *entry,struct intel_pmt_namespace *ns); + +int intel_pmt_add_endpoint (struct intel_vsec_device *ivdev, +struct intel_pmt_entry *entry); +void intel_pmt_release_endpoint (struct class_endpoint *ep); +#endif
drivers/platform/x86/intel/pmt/telemetry.c +9 -42
107 lines not on this page · raw message
drivers/platform/x86/intel/pmt/telemetry.h +9 -14
@@ -2,6 +2,8 @@#ifndef _TELEMETRY_H#define _TELEMETRY_H +#include "class.h" +/* Telemetry types */ #define PMT_TELEM_TELEMETRY 0#define PMT_TELEM_CRASHLOG 1
@@ -9,16 +11,9 @@struct telem_endpoint ;struct pci_dev ; -struct telem_header { -u8 access_type; -u16 size; -u32 guid; -u32 base_offset; -}; -struct telem_endpoint_info {struct pci_dev *pdev; -struct telem_header header; +struct class_header header; };/**
@@ -47,7 +42,7 @@ unsigned long pmt_telem_get_next_endpoint(unsigned long start);* * endpoint - On success returns pointer to the telemetry endpoint * * -ENXIO - telemetry endpoint not found */ -struct telem_endpoint *pmt_telem_register_endpoint (int devid); +struct class_endpoint *pmt_telem_register_endpoint (int devid);/** * pmt_telem_unregister_endpoint() - Unregister a telemetry endpoint
@@ -55,7 +50,7 @@ struct telem_endpoint *pmt_telem_register_endpoint(int devid);* * Decrements the kref usage counter for the endpoint. */ -void pmt_telem_unregister_endpoint (struct telem_endpoint *ep); +void pmt_telem_unregister_endpoint (struct class_endpoint *ep);/** * pmt_telem_get_endpoint_info() - Get info for an endpoint from its devid
@@ -80,8 +75,8 @@ int pmt_telem_get_endpoint_info(int devid, struct telem_endpoint_info *info);* * endpoint - On success returns pointer to the telemetry endpoint * * -ENXIO - telemetry endpoint not found */ -struct telem_endpoint *pmt_telem_find_and_register_endpoint (struct pci_dev *pcidev, -u32 guid,u16 pos); +struct class_endpoint *pmt_telem_find_and_register_endpoint (struct pci_dev *pcidev, +u32 guid,u16 pos);/** * pmt_telem_read() - Read qwords from counter sram using sample id
@@ -101,7 +96,7 @@ struct telem_endpoint *pmt_telem_find_and_register_endpoint(struct pci_dev *pcid* * -EPIPE - The device was removed during the read. Data written * but should be considered invalid. */ -int pmt_telem_read (struct telem_endpoint *ep,u32 id,u64 *data,u32 count); +int pmt_telem_read (struct class_endpoint *ep,u32 id,u64 *data,u32 count);/** * pmt_telem_read32() - Read qwords from counter sram using sample id
@@ -121,6 +116,6 @@ int pmt_telem_read(struct telem_endpoint *ep, u32 id, u64 *data, u32 count);* * -EPIPE - The device was removed during the read. Data written * but should be considered invalid. */ -int pmt_telem_read32 (struct telem_endpoint *ep,u32 id,u32 *data,u32 count); +int pmt_telem_read32 (struct class_endpoint *ep,u32 id,u32 *data,u32 count);#endif
Signature · 1 line
2.49.0
PATCH v3 2/11 platform/x86/intel/pmt: crashlog binary file endpoint
In reply to a message not in the archiveUsage of the intel_pmt_read() for binary sysfs, requires an allocated endpoint struct. The crashlog driver does not allocate the endpoint.
Without the ep, the crashlog usage causes the following NULL pointer exception:
BUG: kernel NULL pointer dereference, address: 0000000000000000 Oops: Oops: 0000 [#1] SMP NOPTI RIP: 0010:intel_pmt_read+0x3b/0x70 [pmt_class] Code: Call Trace: <TASK> ? sysfs_kf_bin_read+0xc0/0xe0 kernfs_fop_read_iter+0xac/0x1a0 vfs_read+0x26d/0x350 ksys_read+0x6b/0xe0 __x64_sys_read+0x1d/0x30 x64_sys_call+0x1bc8/0x1d70 do_syscall_64+0x6d/0x110
Add the endpoint information to the crashlog driver to avoid the NULL pointer exception.
--- drivers/platform/x86/intel/pmt/crashlog.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/pmt/crashlog.c +7 -2
@@ -252,6 +252,7 @@ static struct intel_pmt_namespace pmt_crashlog_ns = { .xa = &crashlog_array, .attr_grp = &pmt_crashlog_group, .pmt_header_decode = pmt_crashlog_header_decode, + .pmt_add_endpoint = intel_pmt_add_endpoint, };/*
@@ -262,8 +263,12 @@ static void pmt_crashlog_remove(struct auxiliary_device *auxdev)struct pmt_crashlog_priv *priv =auxiliary_get_drvdata (auxdev);int i; -for (i =0 ; i < priv->num_entries; i++) -intel_pmt_dev_destroy (&priv->entry[i].entry, &pmt_crashlog_ns); +for (i =0 ; i < priv->num_entries; i++) { +struct intel_pmt_entry *entry = &priv->entry[i].entry; + +intel_pmt_release_endpoint (entry->ep); +intel_pmt_dev_destroy (entry, &pmt_crashlog_ns); + } } static int pmt_crashlog_probe(struct auxiliary_device *auxdev,
Signature · 1 line
2.49.0