Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _INTEL_VSEC_H
3#define _INTEL_VSEC_H
4
5#include <linux/auxiliary_bus.h>
6#include <linux/bits.h>
7#include <linux/err.h>
8#include <linux/intel_pmt_features.h>
9
10/*
11 * VSEC_CAP_UNUSED is reserved. It exists to prevent zero initialized
12 * intel_vsec devices from being automatically set to a known
13 * capability with ID 0
14 */
15#define VSEC_CAP_UNUSED BIT(0)
16#define VSEC_CAP_TELEMETRY BIT(1)
17#define VSEC_CAP_WATCHER BIT(2)
18#define VSEC_CAP_CRASHLOG BIT(3)
19#define VSEC_CAP_SDSI BIT(4)
20#define VSEC_CAP_TPMI BIT(5)
21#define VSEC_CAP_DISCOVERY BIT(6)
22#define VSEC_FEATURE_COUNT 7
23
24/* Intel DVSEC offsets */
25#define INTEL_DVSEC_ENTRIES 0xA
26#define INTEL_DVSEC_SIZE 0xB
27#define INTEL_DVSEC_TABLE 0xC
28#define INTEL_DVSEC_TABLE_BAR(x) ((x) & GENMASK(2, 0))
29#define INTEL_DVSEC_TABLE_OFFSET(x) ((x) & GENMASK(31, 3))
30#define TABLE_OFFSET_SHIFT 3
31
32struct device;
33struct pci_dev;
34struct resource;
35
36enum intel_vsec_disc_source {
37 INTEL_VSEC_DISC_PCI, /* PCI, default */
38 INTEL_VSEC_DISC_ACPI, /* ACPI */
39};
40
41enum intel_vsec_id {
42 VSEC_ID_TELEMETRY = 2,
43 VSEC_ID_WATCHER = 3,
44 VSEC_ID_CRASHLOG = 4,
45 VSEC_ID_DISCOVERY = 12,
46 VSEC_ID_SDSI = 65,
47 VSEC_ID_TPMI = 66,
48};
49
50/**
51 * struct intel_vsec_header - Common fields of Intel VSEC and DVSEC registers.
52 * @rev: Revision ID of the VSEC/DVSEC register space
53 * @length: Length of the VSEC/DVSEC register space
54 * @id: ID of the feature
55 * @num_entries: Number of instances of the feature
56 * @entry_size: Size of the discovery table for each feature
57 * @tbir: BAR containing the discovery tables
58 * @offset: BAR offset of start of the first discovery table
59 */
60struct intel_vsec_header {
61 u8 rev;
62 u16 length;
63 u16 id;
64 u8 num_entries;
65 u8 entry_size;
66 u8 tbir;
67 u32 offset;
68};
69
70enum intel_vsec_quirks {
71 /* Watcher feature not supported */
72 VSEC_QUIRK_NO_WATCHER = BIT(0),
73
74 /* Crashlog feature not supported */
75 VSEC_QUIRK_NO_CRASHLOG = BIT(1),
76
77 /* Use shift instead of mask to read discovery table offset */
78 VSEC_QUIRK_TABLE_SHIFT = BIT(2),
79
80 /* DVSEC not present (provided in driver data) */
81 VSEC_QUIRK_NO_DVSEC = BIT(3),
82
83 /* Platforms requiring quirk in the auxiliary driver */
84 VSEC_QUIRK_EARLY_HW = BIT(4),
85};
86
87/**
88 * struct pmt_callbacks - Callback infrastructure for PMT devices
89 * @read_telem: when specified, called by client driver to access PMT
90 * data (instead of direct copy).
91 * * dev: device reference for the callback's use
92 * * guid: ID of data to acccss
93 * * data: buffer for the data to be copied
94 * * off: offset into the requested buffer
95 * * count: size of buffer
96 */
97struct pmt_callbacks {
98 int (*read_telem)(struct device *dev, u32 guid, u64 *data, loff_t off, u32 count);
99};
100
101struct vsec_feature_dependency {
102 unsigned long feature;
103 unsigned long supplier_bitmap;
104};
105
106/**
107 * struct intel_vsec_platform_info - Platform specific data
108 * @parent: parent device in the auxbus chain
109 * @headers: list of headers to define the PMT client devices to create
110 * @deps: array of feature dependencies
111 * @acpi_disc: ACPI discovery tables, each entry is two QWORDs
112 * in little-endian format as defined by the PMT ACPI spec.
113 * Valid only when @provider == INTEL_VSEC_DISC_ACPI.
114 * @src: source of discovery table data
115 * @priv_data: private data, usable by parent devices, currently a callback
116 * @caps: bitmask of PMT capabilities for the given headers
117 * @quirks: bitmask of VSEC device quirks
118 * @base_addr: allow a base address to be specified (rather than derived)
119 * @num_deps: Count feature dependencies
120 */
121struct intel_vsec_platform_info {
122 struct device *parent;
123 struct intel_vsec_header **headers;
124 const struct vsec_feature_dependency *deps;
125 u32 (*acpi_disc)[4];
126 enum intel_vsec_disc_source src;
127 void *priv_data;
128 unsigned long caps;
129 unsigned long quirks;
130 u64 base_addr;
131 int num_deps;
132};
133
134/**
135 * struct intel_vsec_device - Auxbus specific device information
136 * @auxdev: auxbus device struct for auxbus access
137 * @dev: struct device associated with the device
138 * @resource: PCI discovery resources (BAR windows), one per discovery
139 * instance. Valid only when @src == INTEL_VSEC_DISC_PCI
140 * @acpi_disc: ACPI discovery tables, each entry is two QWORDs
141 * in little-endian format as defined by the PMT ACPI spec.
142 * Valid only when @src == INTEL_VSEC_DISC_ACPI.
143 * @src: source of discovery table data
144 * @ida: id reference
145 * @num_resources: number of resources
146 * @id: xarray id
147 * @priv_data: any private data needed
148 * @priv_data_size: size of private data area
149 * @quirks: specified quirks
150 * @base_addr: base address of entries (if specified)
151 * @cap_id: the enumerated id of the vsec feature
152 */
153struct intel_vsec_device {
154 struct auxiliary_device auxdev;
155 struct device *dev;
156 struct resource *resource;
157 u32 (*acpi_disc)[4];
158 enum intel_vsec_disc_source src;
159 struct ida *ida;
160 int num_resources;
161 int id; /* xa */
162 void *priv_data;
163 size_t priv_data_size;
164 unsigned long quirks;
165 u64 base_addr;
166 unsigned long cap_id;
167};
168
169/**
170 * struct oobmsm_plat_info - Platform information for a device instance
171 * @cdie_mask: Mask of all compute dies in the partition
172 * @package_id: CPU Package id
173 * @partition: Package partition id when multiple VSEC PCI devices per package
174 * @segment: PCI segment ID
175 * @bus_number: PCI bus number
176 * @device_number: PCI device number
177 * @function_number: PCI function number
178 *
179 * Structure to store platform data for a OOBMSM device instance.
180 */
181struct oobmsm_plat_info {
182 u16 cdie_mask;
183 u8 package_id;
184 u8 partition;
185 u8 segment;
186 u8 bus_number;
187 u8 device_number;
188 u8 function_number;
189};
190
191struct telemetry_region {
192 struct oobmsm_plat_info plat_info;
193 void __iomem *addr;
194 size_t size;
195 u32 guid;
196 u32 num_rmids;
197};
198
199struct pmt_feature_group {
200 enum pmt_feature_id id;
201 int count;
202 struct kref kref;
203 struct telemetry_region regions[];
204};
205
206int intel_vsec_add_aux(struct device *parent,
207 struct intel_vsec_device *intel_vsec_dev,
208 const char *name);
209
210static inline struct intel_vsec_device *dev_to_ivdev(struct device *dev)
211{
212 return container_of(dev, struct intel_vsec_device, auxdev.dev);
213}
214
215static inline struct intel_vsec_device *auxdev_to_ivdev(struct auxiliary_device *auxdev)
216{
217 return container_of(auxdev, struct intel_vsec_device, auxdev);
218}
219
220#if IS_ENABLED(CONFIG_INTEL_VSEC)
221int intel_vsec_register(struct device *dev,
222 const struct intel_vsec_platform_info *info);
223int intel_vsec_set_mapping(struct oobmsm_plat_info *plat_info,
224 struct intel_vsec_device *vsec_dev);
225struct oobmsm_plat_info *intel_vsec_get_mapping(struct pci_dev *pdev);
226#else
227static inline int intel_vsec_register(struct device *dev,
228 const struct intel_vsec_platform_info *info)
229{
230 return -ENODEV;
231}
232static inline int intel_vsec_set_mapping(struct oobmsm_plat_info *plat_info,
233 struct intel_vsec_device *vsec_dev)
234{
235 return -ENODEV;
236}
237static inline struct oobmsm_plat_info *intel_vsec_get_mapping(struct pci_dev *pdev)
238{
239 return ERR_PTR(-ENODEV);
240}
241#endif
242
243#if IS_ENABLED(CONFIG_INTEL_PMT_TELEMETRY)
244struct pmt_feature_group *
245intel_pmt_get_regions_by_feature(enum pmt_feature_id id);
246
247void intel_pmt_put_feature_group(struct pmt_feature_group *feature_group);
248#else
249static inline struct pmt_feature_group *
250intel_pmt_get_regions_by_feature(enum pmt_feature_id id)
251{
252 return ERR_PTR(-ENODEV);
253}
254
255static inline void
256intel_pmt_put_feature_group(struct pmt_feature_group *feature_group) {}
257#endif
258
259#endif