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