Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1 | /* |
| 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 |
| 18 | extern "C" { |
| 19 | #endif |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 20 | #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. Bills | a2ceec2 | 2020-05-05 13:16:00 -0700 | [diff] [blame] | 28 | // 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. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 32 | typedef enum |
| 33 | { |
| 34 | skx = 0x00050650, |
| 35 | icx = 0x000606A0, |
| 36 | } CPUModel; |
| 37 | |
| 38 | // PECI Status Codes |
| 39 | typedef 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 |
| 51 | typedef 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 | |
| 68 | typedef 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 | |
| 88 | typedef enum |
| 89 | { |
| 90 | MMIO_DWORD_OFFSET = 0x05, |
| 91 | MMIO_QWORD_OFFSET = 0x06, |
| 92 | } EEndPtMmioAddrType; |
| 93 | |
| 94 | // Find the specified PCI bus number value |
| 95 | EPECIStatus 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 |
| 99 | EPECIStatus peci_GetTemp(uint8_t target, int16_t* temperature); |
| 100 | |
| 101 | // Provides read access to the package configuration space within the processor |
| 102 | EPECIStatus 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 |
| 107 | EPECIStatus 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 |
| 112 | EPECIStatus 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 |
| 117 | EPECIStatus 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 |
| 122 | EPECIStatus 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 |
| 126 | EPECIStatus 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 |
| 131 | EPECIStatus 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 |
| 137 | EPECIStatus 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 |
| 143 | EPECIStatus 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 |
| 150 | EPECIStatus 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 |
| 156 | EPECIStatus 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 |
| 163 | EPECIStatus 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 |
| 170 | EPECIStatus 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 |
| 177 | EPECIStatus 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 |
| 185 | EPECIStatus 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 |
| 193 | EPECIStatus 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 |
| 199 | EPECIStatus 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 |
| 206 | EPECIStatus 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 |
| 213 | EPECIStatus 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 |
| 221 | EPECIStatus 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 |
| 229 | EPECIStatus 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 |
| 235 | EPECIStatus 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 |
| 241 | EPECIStatus 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 |
| 247 | EPECIStatus 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 | |
| 251 | EPECIStatus peci_Lock(int* peci_fd, int timeout_ms); |
| 252 | void peci_Unlock(int peci_fd); |
| 253 | EPECIStatus peci_Ping(uint8_t target); |
| 254 | EPECIStatus peci_Ping_seq(uint8_t target, int peci_fd); |
| 255 | EPECIStatus peci_GetCPUID(const uint8_t clientAddr, CPUModel* cpuModel, |
| 256 | uint8_t* stepping, uint8_t* cc); |
| 257 | |
| 258 | #ifdef __cplusplus |
| 259 | } |
| 260 | #endif |