blob: cb145e3b7f33ff6203e4427143c7146e4357300e [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,
36} CPUModel;
37
38// PECI Status Codes
39typedef enum
40{
41 PECI_CC_SUCCESS = 0,
42 PECI_CC_INVALID_REQ,
43 PECI_CC_HW_ERR,
44 PECI_CC_DRIVER_ERR,
45 PECI_CC_CPU_NOT_PRESENT,
46 PECI_CC_MEM_ERR,
47 PECI_CC_TIMEOUT,
48} EPECIStatus;
49
50// PECI Timeout Options
51typedef enum
52{
53 PECI_WAIT_FOREVER = -1,
54 PECI_NO_WAIT = 0,
55} EPECITimeout;
56
57#define PECI_TIMEOUT_RESOLUTION_MS 10 // 10 ms
58#define PECI_TIMEOUT_MS 100 // 100 ms
59
60// VCU Index and Sequence Paramaters
61#define VCU_SET_PARAM 0x0001
62#define VCU_READ 0x0002
63#define VCU_OPEN_SEQ 0x0003
64#define VCU_CLOSE_SEQ 0x0004
65#define VCU_ABORT_SEQ 0x0005
66#define VCU_VERSION 0x0009
67
68typedef enum
69{
70 VCU_READ_LOCAL_CSR_SEQ = 0x2,
71 VCU_READ_LOCAL_MMIO_SEQ = 0x6,
72 VCU_EN_SECURE_DATA_SEQ = 0x14,
73 VCU_CORE_MCA_SEQ = 0x10000,
74 VCU_UNCORE_MCA_SEQ = 0x10000,
75 VCU_IOT_BRKPT_SEQ = 0x10010,
76 VCU_MBP_CONFIG_SEQ = 0x10026,
77 VCU_PWR_MGT_SEQ = 0x1002a,
78 VCU_CRASHDUMP_SEQ = 0x10038,
79 VCU_ARRAY_DUMP_SEQ = 0x20000,
80 VCU_SCAN_DUMP_SEQ = 0x20008,
81 VCU_TOR_DUMP_SEQ = 0x30002,
82 VCU_SQ_DUMP_SEQ = 0x30004,
83 VCU_UNCORE_CRASHDUMP_SEQ = 0x30006,
84} EPECISequence;
85
86#define MBX_INDEX_VCU 128 // VCU Index
87
88typedef enum
89{
90 MMIO_DWORD_OFFSET = 0x05,
91 MMIO_QWORD_OFFSET = 0x06,
92} EEndPtMmioAddrType;
93
94// Find the specified PCI bus number value
95EPECIStatus FindBusNumber(uint8_t u8Bus, uint8_t u8Cpu, uint8_t* pu8BusValue);
96
97// Gets the temperature from the target
98// Expressed in signed fixed point value of 1/64 degrees celsius
99EPECIStatus peci_GetTemp(uint8_t target, int16_t* temperature);
100
101// Provides read access to the package configuration space within the processor
102EPECIStatus peci_RdPkgConfig(uint8_t target, uint8_t u8Index, uint16_t u16Value,
103 uint8_t u8ReadLen, uint8_t* pPkgConfig,
104 uint8_t* cc);
105
106// Allows sequential RdPkgConfig with the provided peci file descriptor
107EPECIStatus peci_RdPkgConfig_seq(uint8_t target, uint8_t u8Index,
108 uint16_t u16Value, uint8_t u8ReadLen,
109 uint8_t* pPkgConfig, int peci_fd, uint8_t* cc);
110
111// Provides write access to the package configuration space within the processor
112EPECIStatus peci_WrPkgConfig(uint8_t target, uint8_t u8Index, uint16_t u16Param,
113 uint32_t u32Value, uint8_t u8WriteLen,
114 uint8_t* cc);
115
116// Allows sequential WrPkgConfig with the provided peci file descriptor
117EPECIStatus peci_WrPkgConfig_seq(uint8_t target, uint8_t u8Index,
118 uint16_t u16Param, uint32_t u32Value,
119 uint8_t u8WriteLen, int peci_fd, uint8_t* cc);
120
121// Provides read access to Model Specific Registers
122EPECIStatus peci_RdIAMSR(uint8_t target, uint8_t threadID, uint16_t MSRAddress,
123 uint64_t* u64MsrVal, uint8_t* cc);
124
125// Provides read access to PCI Configuration space
126EPECIStatus peci_RdPCIConfig(uint8_t target, uint8_t u8Bus, uint8_t u8Device,
127 uint8_t u8Fcn, uint16_t u16Reg, uint8_t* pPCIReg,
128 uint8_t* cc);
129
130// Allows sequential RdPCIConfig with the provided peci file descriptor
131EPECIStatus peci_RdPCIConfig_seq(uint8_t target, uint8_t u8Bus,
132 uint8_t u8Device, uint8_t u8Fcn,
133 uint16_t u16Reg, uint8_t* pPCIData,
134 int peci_fd, uint8_t* cc);
135
136// Provides read access to the local PCI Configuration space
137EPECIStatus peci_RdPCIConfigLocal(uint8_t target, uint8_t u8Bus,
138 uint8_t u8Device, uint8_t u8Fcn,
139 uint16_t u16Reg, uint8_t u8ReadLen,
140 uint8_t* pPCIReg, uint8_t* cc);
141
142// Allows sequential RdPCIConfigLocal with the provided peci file descriptor
143EPECIStatus peci_RdPCIConfigLocal_seq(uint8_t target, uint8_t u8Bus,
144 uint8_t u8Device, uint8_t u8Fcn,
145 uint16_t u16Reg, uint8_t u8ReadLen,
146 uint8_t* pPCIReg, int peci_fd,
147 uint8_t* cc);
148
149// Provides write access to the local PCI Configuration space
150EPECIStatus peci_WrPCIConfigLocal(uint8_t target, uint8_t u8Bus,
151 uint8_t u8Device, uint8_t u8Fcn,
152 uint16_t u16Reg, uint8_t DataLen,
153 uint32_t DataVal, uint8_t* cc);
154
155// Provides read access to PCI configuration space
156EPECIStatus peci_RdEndPointConfigPci(uint8_t target, uint8_t u8Seg,
157 uint8_t u8Bus, uint8_t u8Device,
158 uint8_t u8Fcn, uint16_t u16Reg,
159 uint8_t u8ReadLen, uint8_t* pPCIData,
160 uint8_t* cc);
161
162// Allows sequential RdEndPointConfig to PCI Configuration space
163EPECIStatus peci_RdEndPointConfigPci_seq(uint8_t target, uint8_t u8Seg,
164 uint8_t u8Bus, uint8_t u8Device,
165 uint8_t u8Fcn, uint16_t u16Reg,
166 uint8_t u8ReadLen, uint8_t* pPCIData,
167 int peci_fd, uint8_t* cc);
168
169// Provides read access to the local PCI configuration space
170EPECIStatus peci_RdEndPointConfigPciLocal(uint8_t target, uint8_t u8Seg,
171 uint8_t u8Bus, uint8_t u8Device,
172 uint8_t u8Fcn, uint16_t u16Reg,
173 uint8_t u8ReadLen, uint8_t* pPCIData,
174 uint8_t* cc);
175
176// Allows sequential RdEndPointConfig to the local PCI Configuration space
177EPECIStatus peci_RdEndPointConfigPciLocal_seq(uint8_t target, uint8_t u8Seg,
178 uint8_t u8Bus, uint8_t u8Device,
179 uint8_t u8Fcn, uint16_t u16Reg,
180 uint8_t u8ReadLen,
181 uint8_t* pPCIData, int peci_fd,
182 uint8_t* cc);
183
184// Provides read access to PCI MMIO space
185EPECIStatus peci_RdEndPointConfigMmio(uint8_t target, uint8_t u8Seg,
186 uint8_t u8Bus, uint8_t u8Device,
187 uint8_t u8Fcn, uint8_t u8Bar,
188 uint8_t u8AddrType, uint64_t u64Offset,
189 uint8_t u8ReadLen, uint8_t* pMmioData,
190 uint8_t* cc);
191
192// Allows sequential RdEndPointConfig to PCI MMIO space
193EPECIStatus peci_RdEndPointConfigMmio_seq(
194 uint8_t target, uint8_t u8Seg, uint8_t u8Bus, uint8_t u8Device,
195 uint8_t u8Fcn, uint8_t u8Bar, uint8_t u8AddrType, uint64_t u64Offset,
196 uint8_t u8ReadLen, uint8_t* pMmioData, int peci_fd, uint8_t* cc);
197
198// Provides write access to the EP local PCI Configuration space
199EPECIStatus peci_WrEndPointPCIConfigLocal(uint8_t target, uint8_t u8Seg,
200 uint8_t u8Bus, uint8_t u8Device,
201 uint8_t u8Fcn, uint16_t u16Reg,
202 uint8_t DataLen, uint32_t DataVal,
203 uint8_t* cc);
204
205// Provides write access to the EP PCI Configuration space
206EPECIStatus peci_WrEndPointPCIConfig(uint8_t target, uint8_t u8Seg,
207 uint8_t u8Bus, uint8_t u8Device,
208 uint8_t u8Fcn, uint16_t u16Reg,
209 uint8_t DataLen, uint32_t DataVal,
210 uint8_t* cc);
211
212// Allows sequential write access to the EP PCI Configuration space
213EPECIStatus peci_WrEndPointConfig_seq(uint8_t target, uint8_t u8MsgType,
214 uint8_t u8Seg, uint8_t u8Bus,
215 uint8_t u8Device, uint8_t u8Fcn,
216 uint16_t u16Reg, uint8_t DataLen,
217 uint32_t DataVal, int peci_fd,
218 uint8_t* cc);
219
220// Provides write access to the EP PCI MMIO space
221EPECIStatus peci_WrEndPointConfigMmio(uint8_t target, uint8_t u8Seg,
222 uint8_t u8Bus, uint8_t u8Device,
223 uint8_t u8Fcn, uint8_t u8Bar,
224 uint8_t u8AddrType, uint64_t u64Offset,
225 uint8_t u8DataLen, uint64_t u64DataVal,
226 uint8_t* cc);
227
228// Allows sequential write access to the EP PCI MMIO space
229EPECIStatus peci_WrEndPointConfigMmio_seq(
230 uint8_t target, uint8_t u8Seg, uint8_t u8Bus, uint8_t u8Device,
231 uint8_t u8Fcn, uint8_t u8Bar, uint8_t u8AddrType, uint64_t u64Offset,
232 uint8_t u8DataLen, uint64_t u64DataVal, int peci_fd, uint8_t* cc);
233
234// Provides access to the Crashdump Discovery API
235EPECIStatus peci_CrashDump_Discovery(uint8_t target, uint8_t subopcode,
236 uint8_t param0, uint16_t param1,
237 uint8_t param2, uint8_t u8ReadLen,
238 uint8_t* pData, uint8_t* cc);
239
240// Provides access to the Crashdump GetFrame API
241EPECIStatus peci_CrashDump_GetFrame(uint8_t target, uint16_t param0,
242 uint16_t param1, uint16_t param2,
243 uint8_t u8ReadLen, uint8_t* pData,
244 uint8_t* cc);
245
246// Provides raw PECI command access
247EPECIStatus peci_raw(uint8_t target, uint8_t u8ReadLen, const uint8_t* pRawCmd,
248 const uint32_t cmdSize, uint8_t* pRawResp,
249 uint32_t respSize);
250
251EPECIStatus peci_Lock(int* peci_fd, int timeout_ms);
252void peci_Unlock(int peci_fd);
253EPECIStatus peci_Ping(uint8_t target);
254EPECIStatus peci_Ping_seq(uint8_t target, int peci_fd);
255EPECIStatus peci_GetCPUID(const uint8_t clientAddr, CPUModel* cpuModel,
256 uint8_t* stepping, uint8_t* cc);
257
258#ifdef __cplusplus
259}
260#endif