1 // SPDX-License-Identifier: GPL-2.0
3 * Intel Platform Monitory Technology Telemetry driver
5 * Copyright (c) 2020, Intel Corporation.
8 * Author: "David E. Box" <david.e.box@linux.intel.com>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/pci.h>
14 #include <linux/slab.h>
15 #include <linux/uaccess.h>
16 #include <linux/overflow.h>
18 #include "intel_pmt_class.h"
20 #define TELEM_DEV_NAME "pmt_telemetry"
22 #define TELEM_SIZE_OFFSET 0x0
23 #define TELEM_GUID_OFFSET 0x4
24 #define TELEM_BASE_OFFSET 0x8
25 #define TELEM_ACCESS(v) ((v) & GENMASK(3, 0))
26 /* size is in bytes */
27 #define TELEM_SIZE(v) (((v) & GENMASK(27, 12)) >> 10)
29 /* Used by client hardware to identify a fixed telemetry entry*/
30 #define TELEM_CLIENT_FIXED_BLOCK_GUID 0x10000000
32 struct pmt_telem_priv
{
34 struct intel_pmt_entry entry
[];
38 * Early implementations of PMT on client platforms have some
39 * differences from the server platforms (which use the Out Of Band
40 * Management Services Module OOBMSM). This list tracks those
41 * platforms as needed to handle those differences. Newer client
42 * platforms are expected to be fully compatible with server.
44 static const struct pci_device_id pmt_telem_early_client_pci_ids
[] = {
45 { PCI_VDEVICE(INTEL
, 0x9a0d) }, /* TGL */
46 { PCI_VDEVICE(INTEL
, 0x467d) }, /* ADL */
50 static bool intel_pmt_is_early_client_hw(struct device
*dev
)
52 struct pci_dev
*parent
= to_pci_dev(dev
->parent
);
54 return !!pci_match_id(pmt_telem_early_client_pci_ids
, parent
);
57 static bool pmt_telem_region_overlaps(struct intel_pmt_entry
*entry
,
60 u32 guid
= readl(entry
->disc_table
+ TELEM_GUID_OFFSET
);
62 if (guid
!= TELEM_CLIENT_FIXED_BLOCK_GUID
)
65 return intel_pmt_is_early_client_hw(dev
);
68 static int pmt_telem_header_decode(struct intel_pmt_entry
*entry
,
69 struct intel_pmt_header
*header
,
72 void __iomem
*disc_table
= entry
->disc_table
;
74 if (pmt_telem_region_overlaps(entry
, dev
))
77 header
->access_type
= TELEM_ACCESS(readl(disc_table
));
78 header
->guid
= readl(disc_table
+ TELEM_GUID_OFFSET
);
79 header
->base_offset
= readl(disc_table
+ TELEM_BASE_OFFSET
);
81 /* Size is measured in DWORDS, but accessor returns bytes */
82 header
->size
= TELEM_SIZE(readl(disc_table
));
87 static DEFINE_XARRAY_ALLOC(telem_array
);
88 static struct intel_pmt_namespace pmt_telem_ns
= {
91 .pmt_header_decode
= pmt_telem_header_decode
,
94 static int pmt_telem_remove(struct platform_device
*pdev
)
96 struct pmt_telem_priv
*priv
= platform_get_drvdata(pdev
);
99 for (i
= 0; i
< priv
->num_entries
; i
++)
100 intel_pmt_dev_destroy(&priv
->entry
[i
], &pmt_telem_ns
);
105 static int pmt_telem_probe(struct platform_device
*pdev
)
107 struct pmt_telem_priv
*priv
;
111 size
= struct_size(priv
, entry
, pdev
->num_resources
);
112 priv
= devm_kzalloc(&pdev
->dev
, size
, GFP_KERNEL
);
116 platform_set_drvdata(pdev
, priv
);
118 for (i
= 0; i
< pdev
->num_resources
; i
++) {
119 struct intel_pmt_entry
*entry
= &priv
->entry
[i
];
121 ret
= intel_pmt_dev_create(entry
, &pmt_telem_ns
, pdev
, i
);
132 pmt_telem_remove(pdev
);
136 static struct platform_driver pmt_telem_driver
= {
138 .name
= TELEM_DEV_NAME
,
140 .remove
= pmt_telem_remove
,
141 .probe
= pmt_telem_probe
,
144 static int __init
pmt_telem_init(void)
146 return platform_driver_register(&pmt_telem_driver
);
148 module_init(pmt_telem_init
);
150 static void __exit
pmt_telem_exit(void)
152 platform_driver_unregister(&pmt_telem_driver
);
153 xa_destroy(&telem_array
);
155 module_exit(pmt_telem_exit
);
157 MODULE_AUTHOR("David E. Box <david.e.box@linux.intel.com>");
158 MODULE_DESCRIPTION("Intel PMT Telemetry driver");
159 MODULE_ALIAS("platform:" TELEM_DEV_NAME
);
160 MODULE_LICENSE("GPL v2");