blob: aa482dbb8e0beeb1f86f059b0346d12282261a01 [file] [log] [blame]
Jason M. Bills7ef5a552020-04-06 14:58:44 -07001/*
2// Copyright (c) 2019 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17#ifdef __cplusplus
18extern "C" {
19#endif
Jason M. Bills7ef5a552020-04-06 14:58:44 -070020#include <inttypes.h>
21#include <stdbool.h>
22
23// PECI Client Address List
24#define MIN_CLIENT_ADDR 0x30
25#define MAX_CLIENT_ADDR 0x37
26#define MAX_CPUS (MAX_CLIENT_ADDR - MIN_CLIENT_ADDR + 1)
27
Jason M. Billsa2ceec22020-05-05 13:16:00 -070028// PECI completion codes from peci-ioctl.h
29#define PECI_DEV_CC_SUCCESS 0x40
30#define PECI_DEV_CC_FATAL_MCA_DETECTED 0x94
31
Jason M. Bills7ef5a552020-04-06 14:58:44 -070032typedef enum
33{
34 skx = 0x00050650,
35 icx = 0x000606A0,
Jonathan Doman6a00e9a2021-11-03 13:55:45 -070036 icxd = 0x000606C0,
37 spr = 0x000806F0,
Jason M. Bills7ef5a552020-04-06 14:58:44 -070038} CPUModel;
39
40// PECI Status Codes
41typedef enum
42{
43 PECI_CC_SUCCESS = 0,
44 PECI_CC_INVALID_REQ,
45 PECI_CC_HW_ERR,
46 PECI_CC_DRIVER_ERR,
47 PECI_CC_CPU_NOT_PRESENT,
48 PECI_CC_MEM_ERR,
49 PECI_CC_TIMEOUT,
50} EPECIStatus;
51
52// PECI Timeout Options
53typedef enum
54{
55 PECI_WAIT_FOREVER = -1,
56 PECI_NO_WAIT = 0,
57} EPECITimeout;
58
59#define PECI_TIMEOUT_RESOLUTION_MS 10 // 10 ms
60#define PECI_TIMEOUT_MS 100 // 100 ms
61
62// VCU Index and Sequence Paramaters
63#define VCU_SET_PARAM 0x0001
64#define VCU_READ 0x0002
65#define VCU_OPEN_SEQ 0x0003
66#define VCU_CLOSE_SEQ 0x0004
67#define VCU_ABORT_SEQ 0x0005
68#define VCU_VERSION 0x0009
69
70typedef enum
71{
72 VCU_READ_LOCAL_CSR_SEQ = 0x2,
73 VCU_READ_LOCAL_MMIO_SEQ = 0x6,
74 VCU_EN_SECURE_DATA_SEQ = 0x14,
75 VCU_CORE_MCA_SEQ = 0x10000,
76 VCU_UNCORE_MCA_SEQ = 0x10000,
77 VCU_IOT_BRKPT_SEQ = 0x10010,
78 VCU_MBP_CONFIG_SEQ = 0x10026,
79 VCU_PWR_MGT_SEQ = 0x1002a,
80 VCU_CRASHDUMP_SEQ = 0x10038,
81 VCU_ARRAY_DUMP_SEQ = 0x20000,
82 VCU_SCAN_DUMP_SEQ = 0x20008,
83 VCU_TOR_DUMP_SEQ = 0x30002,
84 VCU_SQ_DUMP_SEQ = 0x30004,
85 VCU_UNCORE_CRASHDUMP_SEQ = 0x30006,
86} EPECISequence;
87
88#define MBX_INDEX_VCU 128 // VCU Index
89
90typedef enum
91{
92 MMIO_DWORD_OFFSET = 0x05,
93 MMIO_QWORD_OFFSET = 0x06,
94} EEndPtMmioAddrType;
95
96// Find the specified PCI bus number value
97EPECIStatus FindBusNumber(uint8_t u8Bus, uint8_t u8Cpu, uint8_t* pu8BusValue);
98
99// Gets the temperature from the target
100// Expressed in signed fixed point value of 1/64 degrees celsius
101EPECIStatus peci_GetTemp(uint8_t target, int16_t* temperature);
102
103// Provides read access to the package configuration space within the processor
104EPECIStatus peci_RdPkgConfig(uint8_t target, uint8_t u8Index, uint16_t u16Value,
105 uint8_t u8ReadLen, uint8_t* pPkgConfig,
106 uint8_t* cc);
107
108// Allows sequential RdPkgConfig with the provided peci file descriptor
109EPECIStatus peci_RdPkgConfig_seq(uint8_t target, uint8_t u8Index,
110 uint16_t u16Value, uint8_t u8ReadLen,
111 uint8_t* pPkgConfig, int peci_fd, uint8_t* cc);
112
113// Provides write access to the package configuration space within the processor
114EPECIStatus peci_WrPkgConfig(uint8_t target, uint8_t u8Index, uint16_t u16Param,
115 uint32_t u32Value, uint8_t u8WriteLen,
116 uint8_t* cc);
117
118// Allows sequential WrPkgConfig with the provided peci file descriptor
119EPECIStatus peci_WrPkgConfig_seq(uint8_t target, uint8_t u8Index,
120 uint16_t u16Param, uint32_t u32Value,
121 uint8_t u8WriteLen, int peci_fd, uint8_t* cc);
122
123// Provides read access to Model Specific Registers
124EPECIStatus peci_RdIAMSR(uint8_t target, uint8_t threadID, uint16_t MSRAddress,
125 uint64_t* u64MsrVal, uint8_t* cc);
126
127// Provides read access to PCI Configuration space
128EPECIStatus peci_RdPCIConfig(uint8_t target, uint8_t u8Bus, uint8_t u8Device,
129 uint8_t u8Fcn, uint16_t u16Reg, uint8_t* pPCIReg,
130 uint8_t* cc);
131
132// Allows sequential RdPCIConfig with the provided peci file descriptor
133EPECIStatus peci_RdPCIConfig_seq(uint8_t target, uint8_t u8Bus,
134 uint8_t u8Device, uint8_t u8Fcn,
135 uint16_t u16Reg, uint8_t* pPCIData,
136 int peci_fd, uint8_t* cc);
137
138// Provides read access to the local PCI Configuration space
139EPECIStatus peci_RdPCIConfigLocal(uint8_t target, uint8_t u8Bus,
140 uint8_t u8Device, uint8_t u8Fcn,
141 uint16_t u16Reg, uint8_t u8ReadLen,
142 uint8_t* pPCIReg, uint8_t* cc);
143
144// Allows sequential RdPCIConfigLocal with the provided peci file descriptor
145EPECIStatus peci_RdPCIConfigLocal_seq(uint8_t target, uint8_t u8Bus,
146 uint8_t u8Device, uint8_t u8Fcn,
147 uint16_t u16Reg, uint8_t u8ReadLen,
148 uint8_t* pPCIReg, int peci_fd,
149 uint8_t* cc);
150
151// Provides write access to the local PCI Configuration space
152EPECIStatus peci_WrPCIConfigLocal(uint8_t target, uint8_t u8Bus,
153 uint8_t u8Device, uint8_t u8Fcn,
154 uint16_t u16Reg, uint8_t DataLen,
155 uint32_t DataVal, uint8_t* cc);
156
157// Provides read access to PCI configuration space
158EPECIStatus peci_RdEndPointConfigPci(uint8_t target, uint8_t u8Seg,
159 uint8_t u8Bus, uint8_t u8Device,
160 uint8_t u8Fcn, uint16_t u16Reg,
161 uint8_t u8ReadLen, uint8_t* pPCIData,
162 uint8_t* cc);
163
164// Allows sequential RdEndPointConfig to PCI Configuration space
165EPECIStatus peci_RdEndPointConfigPci_seq(uint8_t target, uint8_t u8Seg,
166 uint8_t u8Bus, uint8_t u8Device,
167 uint8_t u8Fcn, uint16_t u16Reg,
168 uint8_t u8ReadLen, uint8_t* pPCIData,
169 int peci_fd, uint8_t* cc);
170
171// Provides read access to the local PCI configuration space
172EPECIStatus peci_RdEndPointConfigPciLocal(uint8_t target, uint8_t u8Seg,
173 uint8_t u8Bus, uint8_t u8Device,
174 uint8_t u8Fcn, uint16_t u16Reg,
175 uint8_t u8ReadLen, uint8_t* pPCIData,
176 uint8_t* cc);
177
178// Allows sequential RdEndPointConfig to the local PCI Configuration space
179EPECIStatus peci_RdEndPointConfigPciLocal_seq(uint8_t target, uint8_t u8Seg,
180 uint8_t u8Bus, uint8_t u8Device,
181 uint8_t u8Fcn, uint16_t u16Reg,
182 uint8_t u8ReadLen,
183 uint8_t* pPCIData, int peci_fd,
184 uint8_t* cc);
185
186// Provides read access to PCI MMIO space
187EPECIStatus peci_RdEndPointConfigMmio(uint8_t target, uint8_t u8Seg,
188 uint8_t u8Bus, uint8_t u8Device,
189 uint8_t u8Fcn, uint8_t u8Bar,
190 uint8_t u8AddrType, uint64_t u64Offset,
191 uint8_t u8ReadLen, uint8_t* pMmioData,
192 uint8_t* cc);
193
194// Allows sequential RdEndPointConfig to PCI MMIO space
195EPECIStatus peci_RdEndPointConfigMmio_seq(
196 uint8_t target, uint8_t u8Seg, uint8_t u8Bus, uint8_t u8Device,
197 uint8_t u8Fcn, uint8_t u8Bar, uint8_t u8AddrType, uint64_t u64Offset,
198 uint8_t u8ReadLen, uint8_t* pMmioData, int peci_fd, uint8_t* cc);
199
200// Provides write access to the EP local PCI Configuration space
201EPECIStatus peci_WrEndPointPCIConfigLocal(uint8_t target, uint8_t u8Seg,
202 uint8_t u8Bus, uint8_t u8Device,
203 uint8_t u8Fcn, uint16_t u16Reg,
204 uint8_t DataLen, uint32_t DataVal,
205 uint8_t* cc);
206
207// Provides write access to the EP PCI Configuration space
208EPECIStatus peci_WrEndPointPCIConfig(uint8_t target, uint8_t u8Seg,
209 uint8_t u8Bus, uint8_t u8Device,
210 uint8_t u8Fcn, uint16_t u16Reg,
211 uint8_t DataLen, uint32_t DataVal,
212 uint8_t* cc);
213
214// Allows sequential write access to the EP PCI Configuration space
215EPECIStatus peci_WrEndPointConfig_seq(uint8_t target, uint8_t u8MsgType,
216 uint8_t u8Seg, uint8_t u8Bus,
217 uint8_t u8Device, uint8_t u8Fcn,
218 uint16_t u16Reg, uint8_t DataLen,
219 uint32_t DataVal, int peci_fd,
220 uint8_t* cc);
221
222// Provides write access to the EP PCI MMIO space
223EPECIStatus peci_WrEndPointConfigMmio(uint8_t target, uint8_t u8Seg,
224 uint8_t u8Bus, uint8_t u8Device,
225 uint8_t u8Fcn, uint8_t u8Bar,
226 uint8_t u8AddrType, uint64_t u64Offset,
227 uint8_t u8DataLen, uint64_t u64DataVal,
228 uint8_t* cc);
229
230// Allows sequential write access to the EP PCI MMIO space
231EPECIStatus peci_WrEndPointConfigMmio_seq(
232 uint8_t target, uint8_t u8Seg, uint8_t u8Bus, uint8_t u8Device,
233 uint8_t u8Fcn, uint8_t u8Bar, uint8_t u8AddrType, uint64_t u64Offset,
234 uint8_t u8DataLen, uint64_t u64DataVal, int peci_fd, uint8_t* cc);
235
236// Provides access to the Crashdump Discovery API
237EPECIStatus peci_CrashDump_Discovery(uint8_t target, uint8_t subopcode,
238 uint8_t param0, uint16_t param1,
239 uint8_t param2, uint8_t u8ReadLen,
240 uint8_t* pData, uint8_t* cc);
241
242// Provides access to the Crashdump GetFrame API
243EPECIStatus peci_CrashDump_GetFrame(uint8_t target, uint16_t param0,
244 uint16_t param1, uint16_t param2,
245 uint8_t u8ReadLen, uint8_t* pData,
246 uint8_t* cc);
247
248// Provides raw PECI command access
249EPECIStatus peci_raw(uint8_t target, uint8_t u8ReadLen, const uint8_t* pRawCmd,
250 const uint32_t cmdSize, uint8_t* pRawResp,
251 uint32_t respSize);
252
253EPECIStatus peci_Lock(int* peci_fd, int timeout_ms);
254void peci_Unlock(int peci_fd);
255EPECIStatus peci_Ping(uint8_t target);
256EPECIStatus peci_Ping_seq(uint8_t target, int peci_fd);
257EPECIStatus peci_GetCPUID(const uint8_t clientAddr, CPUModel* cpuModel,
258 uint8_t* stepping, uint8_t* cc);
Anna Platash03d7dae2021-02-05 13:52:05 +0100259void peci_SetDevName(char* peci_dev);
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700260
261#ifdef __cplusplus
262}
263#endif